import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[^\\n.!?:]*(?:thanks[ .?!]*$|thank[ -]you[ .?!]*$|(?:please|help|suggest(?:ions)|thanks)\\b[^\\n.!?:]*\\b(?:help|ap+reciat\\w*|me|advan\\w*|a ?lot)\\b[^\\n.!?:]*)[.!?]*[ ]*";
final String string = "I don't know what's going on. Any help would be appreciated. How can I do this?\n\n"
+ "Any suggestions are appreciated :)\n\n"
+ "Please help me, i will thank you. How I do this?\n\n"
+ "I hope you guys can help me. Thanks for any help.\n\n"
+ "All suggestions are appreciated, thanks\n\n"
+ "Thanks in advance.\n\n"
+ "Could you help me?\n\n"
+ "I hope you can please help me buddy!\n\n"
+ "please help\n\n"
+ "Can someone please guide me where I am going wrong ?\n\n"
+ "I have no teacher or any instructor because I am learning programming on my own, so please any help is appreciated. Thanks\n\n"
+ "thanks in advance!\n\n"
+ "thanks in advantage!\n\n"
+ "Thanks in advance!\n\n"
+ "kindly help me with the step by step solution.. thanks in advance\n\n"
+ "__Thanks in advance.__\n\n"
+ "Thanks a lot!\n\n"
+ "Thank you!!!\n\n"
+ " also id like to thank you for any help in advance. let me first state that i am aware of possible security issues and will address those accordingly.\n\n"
+ "thanks!!\n\n"
+ "Do Not Match:\n\n"
+ "Software for tanks. It would please my boss. \n\n"
+ "Please look at this example.\n\n"
+ "Thanks to Microsoft, I can no longer log in to my email.\n\n"
+ "Please stop sending me emails Microsoft! << Nobody has ever said that on SO.\n\n"
+ "Please don't ever do this. << This is a common statement in PHP/MySQL answers!\n\n"
+ "Please don't tell me you are using regular expressions to validate urls when there's the Uri.TryCreate method.\n\n"
+ "Thank you to AndrewMalinnkov for the answer!";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | 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