0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I checked with this tester link Is it possible to return just the first match?
@SzékelyDávid, add a replacement and you will see that the empty space between () is also matched. Ofc you can get just the first match. Here is everything put together.
Oh i see :D Thanks for your time!
@SzékelyDávid, yw (:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.