fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String text = "Assert.assertEquals(/\"Hello World, /\" + \"Hello!\", expectedVar2, actualVar)";
  9. String pattern = "Assert\\.assertEquals\\((?>(?:[^,]*\"(?:[^,]*,)+[^,]*\")+|[^,]+),\\s*([^,]+)";
  10. Pattern r = Pattern.compile(pattern);
  11. Matcher m = r.matcher(text);
  12. if (m.find()) {
  13. System.out.println("MATCH FOUND: " + m.group(1));
  14. } else {
  15. System.out.println("NO MATCH");
  16. }
  17. }
  18. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
MATCH FOUND: expectedVar2