简体   繁体   中英

Match all pattent in regex - java

I am trying to find method calls in Java source code.

Here is my current attempt:

Subject:

 exec.execute(new EngineRobot(robotPool)); 

Pattern:

 ((?!while|if|for\\b)\\b\\w+)\\s*\\((.*)\\) 

Demo

I want to find both method names ("execute" and "EngineRobot") but it only returns "execute".

If I understand correctly, you want to match both of the words using one regex. Just use a lookahead for that so that the regex doesn't consume too many characters.

((?!while|if|for\b)\b\w+)\s*(?=\((.*)\))

Demo

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