Having this Pattern for a regular expression :
Pattern p = Pattern.compile("[^\\.](?s)executeRule\\(\\s*?(.+?),\\s*?('.+?'),\\s*(\\[.+?\\]\\s*\\);)");
I have a text like :
setSomething(false);
executeRule(document, 'PublishDocumentsToEmail', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
);
System.out.println("bla");
executeRule(document, 'PublishDocumentsToJMS', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
);
I want to find the sequences that contain the executeRule pattern.
My regular expression successfully finds only the first pattern occurence; all the patterns that follow after this first pattern will contain the previous patterns.
E.g. the first time I parse I find
executeRule(document, 'PublishDocumentsToEmail', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
);
I do some replacements on the pattern so it becomes
executeRule(document, 'PublishDocumentsToEmail', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
,crs
);
After this I recursively call the same parsing method with the new text which is
setSomething(false);
executeRule(document, 'PublishDocumentsToEmail', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
,crs
);
System.out.println("bla");
executeRule(document, 'PublishDocumentsToJMS', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
);
and my regexp will match the entire section from
executeRule(document, 'PublishDocumentsToEmail', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
,crs
);
System.out.println("bla");
executeRule(document, 'PublishDocumentsToJMS', [
'xmlMapping':'xmlmapping.TagRegLike',
'emailAddress':'EMAIL(mymail@mail.com)',
'emailSubject':'Test',
'emailText':'test',
'filenameSuffix':'test']
);
How can I get it to match only my second pattern ?
Thx
I didn’t thoroughly read your examples but you could either use
\Gin your pattern to start after the last match or just loop over the matches when usingMatcher#find().Hope that helps.
Update:
Why would you call that recursively? I don’t see any recursion so you might just iterate over the matches you found in the first call.