hEngi
hEngi

Reputation: 915

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!

Upvotes: 0

Views: 41

Answers (1)

ndnenkov
ndnenkov

Reputation: 36110

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.

Upvotes: 1

Related Questions