fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class DummyTester {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. checkRegex("userName eq \"bjensen\""); // returning Matches True
  9. checkRegex("(userName eq \"bjensen\" and familyName co \"O'Malley\")"); // returning matches False
  10. checkRegex("(userName eq \"bjensen\" and familyName co \"O'Malley\" AND userName eq \"bjensen\" AND familyName co \"O'Malley\")"); // returning matches False
  11.  
  12. }
  13.  
  14. static String checkRegex(String tester) {
  15.  
  16. String regex ="(?i)[a-z][a-z0-9]*\\s+(?:co|eq|gt)\\s*\"[^\"]*\"(?:\\s+(?:and|or)\\s+[a-z][a-z0-9]*\\s+(?:co|eq|gt)\\s*\"[^\"]*\")*";
  17. System.out.println("The input regex sis : "+regex);
  18. System.out.println("The input String sis : "+tester);
  19. Pattern p = Pattern.compile(regex);
  20. Matcher m = p.matcher(tester);
  21. boolean b = m.find();
  22. System.out.println("finder is : "+ b);
  23. if (b) {
  24. String s = m.group();
  25. System.out.println(s);
  26. return s;
  27. }
  28. return null;
  29. }
  30.  
  31. }
Success #stdin #stdout 0.12s 36684KB
stdin
Standard input is empty
stdout
The input regex  sis : (?i)[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*"(?:\s+(?:and|or)\s+[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*")*
The input String sis : userName eq "bjensen"
finder is   : true
userName eq "bjensen"
The input regex  sis : (?i)[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*"(?:\s+(?:and|or)\s+[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*")*
The input String sis : (userName eq "bjensen" and familyName co "O'Malley")
finder is   : true
userName eq "bjensen" and familyName co "O'Malley"
The input regex  sis : (?i)[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*"(?:\s+(?:and|or)\s+[a-z][a-z0-9]*\s+(?:co|eq|gt)\s*"[^"]*")*
The input String sis : (userName eq "bjensen" and familyName co "O'Malley" AND userName eq "bjensen" AND familyName co "O'Malley")
finder is   : true
userName eq "bjensen" and familyName co "O'Malley" AND userName eq "bjensen" AND familyName co "O'Malley"