简体   繁体   中英

Regular Expression in java to get parameters from javascript methods

Long story short, i would like to get the parameters list from JavaScript methods in Java. It works well if i got any parameters, but if the parameter list is empty it's just not working. For example

function() { return fn.num(tra.getMaster_id(fg)+1)

My regular expression is:

(?<=\({1}).*?(?=\){1})

The result i get:

tra.getMaster_id(fg

The result i want is the empty space between the () .

If i test it with Here everything is fine, but in java it didn't working yet :(

I would appreciate any ideas!

First of all, you don't need {1} repetition quantifiers, everything is repeated just once by default. Secondly, since regexes in java are just strings that get interpreted, you have to escape escaping slashes ( \\ ):

(?<=\\().*?(?=\\))

Thirdly, you are getting the match that you want, it is just that there are more than one matches in this case. You are currently fetching the last one and not the first one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM