import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\A(what[\\W_]+is[\\W_]+your[\\W_]+name[\\W_]*){10,}";
final String string = "First off, sorry for not reviewing quickly. I put off doing so a bit when I first saw this, then ended up quite tired and went to sleep.\n\n"
+ "This seems quite similar in intent to the existing rule \"repeating words in {}\". Are there cases where that rule and this rule will both match the same text?\n\n"
+ "It looks like you found and fixed the first issue I had, which was the redundant detection name. And fixed the second issue (that post bodies start with an HTML tag). Just FYI: a `<p>` is not the only HTML tag which can start a post body, but it is, by far, the most common.\n\n"
+ "##### In the version as of the point you removed it from SD:\n\n"
+ "you use `(.+?)` in the second regex. That seems over-broad. I'd be much more comfortable if there was a relatively/moderately short limit to the number of characters there. Perhaps a couple/few hundred characters? However, that's probably not all that critical.\n\n"
+ "The code:\n"
+ "```\n"
+ "repeats = regex.match(r\"\\A(\\w+(?:\\W+\\w+){%i}\\W*){10,}\" % (len(period.groups(0)[0].split()) + 1), s)\n"
+ "```\n"
+ "doesn't appear to do what you're intending. It doesn't end up looking for a repeating pattern, it just looks for a bunch of words, which would match nearly anything and return the last portion of the text.\n\n"
+ "For example, on [this post](https://metasmoke.erwaysoftware.com/post/366947), the first regex does [this](https://regex101.com/r/tTnkxh/1), which then results in the second regex being `\\Awhat\\W+is\\W+your\\W+(.+?)what\\W+is\\W+your\\b` and is doing [this](https://regex101.com/r/0oVnFf/1). That makes the final regex be `\\A(\\w+(?:\\W+\\w+){2}\\W*){10,}`, which is doing [this on that text](https://regex101.com/r/RI5ePw/1). However, it's going to match anything. For example, using the text of this comment as the body text, it does [this]().";
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));
}
}
}
}
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