Regex string matching question
Posted on 2006-06-08
If I want to replacethe string 'start abcdefg 12345 6blahblahblah end' using a regex, where that string might in in much larger string I can use
Pattern p = Pattern.compile(''start .+end");
Matcher m = p.matcher(huge_chunk_of_text);
String changedInput = m.replaceAll(replacementText);
This works fine if the string I'm looking for only occurs once in huge_chunk_of_text but if it occurs more than once then the regex i'm using,'start .+end" will only fine one match, eg 'start abcdefg 12345 6blahblahblah end blah blah start abcdefg 12345 6blahblahblah end'' should be two matches not one. How do I specify that there should not be another 'start' before 'end', I have tried using [start][+.][^start][end] but that doesn't work.