I need to parse big javascript code (I write app in Python) and find definitions of some constants in it. All constants are defined like this:
function(e) {
e[e.CONST_1 = VALUE_1] = "CONST_1",
e[e.CONST_2 = VALUE_2] = "CONST_2",
e[e.CONST_3 = VALUE_3] = "CONST_3"
}(e.ConstGroupName_1 || (e.ConstGroupName_1 = {})),
Of course all code is minimized, so there are no spaces, newlines and etc...
function(e){e[e.CONST_1=1]="CONST_1",e[e.CONST_2=0]="CONST_2",e[e.CONST_3=1]="CONST_3"}(e.ConstGroupName_1||(e.ConstGroupName_1={}))
So basicly i need to get pairs CONST_1 = VALUE_1, CONST_2 = VALUE_2, CONST_3 = VALUE_3. To parse const values i use this regex \[e\.(.*?)=(\d)\]
To match const group I'm trying to use (?<=function\(e\){)(.*)(?=ConstGroupName_1)
Currently I've 2 problems:
- This
(?<=function\(e\){)(.*)(?=ConstGroupName_1)works fine, until there are a lot offunction(e){in code and it matches first occurance, not last one (nearest toConstGroupName_1block) - I don't understand how to combine both expressions into single regex
UPD: Problem 1 is partially fixed:
(?:function\(e\)){((?:(?!function).)*?)(?:}\(e.ConstGroupName_1)