So regular expressions seem to match in the longest match. For instance:
public static void main(String[] args) { String s = "ClarkRalphKentGuyGreenGardnerClarkSupermanKent"; Pattern p = Pattern.compile("Clark.*Kent", Pattern.CASE_INSENSITIVE); Matcher myMatcher = p.matcher(s); int i = 1; while (myMatcher.find()) { System.out.println(i++ + ". " + myMatcher.group()); } }
generates output
- ClarkRalphKentGuyGreenGardnerClarkSupermanKent
I need this conclusion
- Clarkralphkent
- ClarkSupermanKent
I tried templates like:
Pattern p = Pattern.compile("Clark[^((Kent)*)]Kent", Pattern.CASE_INSENSITIVE);
which do not work, but you see what I'm trying to say. I want the line from Clark to Kent not to contain Kent.
This line:
ClarkRalphKentGuyGreenGardnerBruceBatmanKent
should generate output
source share