import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "r";
final String string = "Ex1. This is a random sentence.1,7,9 This is a sentence followed by it.\n"
+ "Output = This is a random sentence. 1,7,9 This is a sentence followed by it.`#space after the period will do.\n"
+ "Ex2. I love football.1,7,24`I also like cricket.\n"
+ "Output = I love football. 1,7,24`I also like cricket.\n\n"
+ "Ex3. ESD for undifferentiated cancers.[1][7]Cancers can be treata\n"
+ "ble.\n"
+ "Output = ESD for undifferentiated cancers. [1][7]Cancers can be treatable. #space after the period\n\n"
+ "EX4. |Age, n (%) | | |< | |\n"
+ "| | | |0.001 | |\n"
+ "| |> 65 years |641 (44.3) |28 (24.8) | |669 (42.9)|\n"
+ "| |? 65 years |806 (55.7) |85 (75.2) | |891 (57.1)|\n"
+ "# Tables should be untouched\n"
+ "EX5.75.6% vs. 54.0% # untouched\n\n"
+ "EX6. ask@to.in # should be untouched\n\n"
+ "EX7. Decimal numbers 22.3456 # should be untouched\n\n"
+ "EX8.";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (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));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html