Reputation: 153
I have big files like this:
f = """
(function ($hx_exp, $g) {
var A = function() { };
$hxCls[1] = $hxCls["A"] = A;
A.__name__ = ["A"];
A.__get = function(d,e) {
return "a";
};
var B = function(a,c) {
this.r = new Func1(a,c);
};
$hxCls[2] = $hxCls["B"] = B;
B.__name__ = ["B"];
B.prototype = {
r: null,
map: function(s,f) { return 0; },
__class__: B
};
}(this));
"""
I want split this text into like this:
var A = function() { };
$hxCls[1] = $hxCls["A"] = A;
A.__name__ = ["A"];
A.__get = function(d,e) {
return "a";
};
I use regexp:
re.findall(r"(^var.+)", txt)
But I fund only lines:
var A = function() { };
var B = function(a,c) {
Maybe someone knows libraries that can break such large JavaScript
files into several others.
Upvotes: 1
Views: 48
Reputation: 9
Try this:
re.finditer(r"var\s\w\s=.*?(?=var\sB|\}\(this\))", txt, re.DOTALL)
Test: https://regex101.com/r/2O6rgN/1/
Upvotes: 1