I have this java code
String msg = "*1*20*11*30*IGNORE*53*40##";
String regex = "\\*1\\*(.*?)\\*11\\*(.*?)\\*(.*?)\\*53\\*(.*?)##";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
for (int i = 0; i < matcher.groupCount(); i++) {
System.out.println(matcher.group((i+1)));
}
}
the output is
20
30
IGNORE
40
How do I have to change the regex, that the String which is IGNORE is ignored? I want to,that anything which is written there not to be found by the matcher. the positions where 20,30,40 is are values for me which I need to extract, IGNORE in my case is any protocol specific counter which has no need for me
\\*1\\*(.*?)\\*11\\*(.*?)\\*(?:(?!IGNORE).)*?\\*53\\*(.*?)##?\\*1\\*(.*?)\\*11\\*(.*?)\\*.*?\\*53\\*(.*?)##?()around a part you don't need? Just remove those.