I have 2 different results betwin regex online and my java code.
My input text:
Examples:
#DATA
|id|author|zip|city|element|
Odl data - Odl data - Odl data
#END
I want change Odl data - Odl data - Odl data (in my example) by foo.
My regex is:
#DATA[\s\S].*[\s\S]([\s\S]*)#END
I want change Group 1 by foo
démo online:
https://regex101.com/r/Nq9fas/2
My java code:
final String regex = "#DATA[\\s\\S].*[\\s\\S]([\\s\\S]*)#END";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
I want keep the 1st line (|id|author|zip|city|element|) but my regex change all data betwin #DATA and #END
