/* Expressões regulares com Java Patterns
http://pt.stackoverflow.com/q/186142/53463 */
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Ideone
{
{
final String regex
= "^[^ab]*+(?=(?:[^b]*b){2})(?:[^a]*a){2}[^a]*$";
"---aabb+++","---bbaa+++","---abab+++","---baba+++",
"---babba++","---bbbbbaa","ababbb++++","ccabcab+++",
"----bcdbaa","-ababd++++","bbbaabbbbb","bbbabbbbbb",
"bbbaaabbbb","baaaaaaaaa","abbbbbbbbb","ccacbcacbc"
};
final Pattern pattern = Pattern.compile(regex);
for (String palavra
: exemplos
) { Matcher matcher = pattern.matcher(palavra);
if (matcher.find()) {
System.
out.
println(palavra
+ " ✔️"); } else {
System.
out.
println(palavra
+ " ✖️️"); }
}
}
}
LyogRXhwcmVzc8O1ZXMgcmVndWxhcmVzIGNvbSBKYXZhIFBhdHRlcm5zCiAgIGh0dHA6Ly9wdC5zdGFja292ZXJmbG93LmNvbS9xLzE4NjE0Mi81MzQ2MyAqLwoKaW1wb3J0IGphdmEudXRpbC5yZWdleC5NYXRjaGVyOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4LlBhdHRlcm47CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJZmluYWwgU3RyaW5nIHJlZ2V4ID0gIl5bXmFiXSorKD89KD86W15iXSpiKXsyfSkoPzpbXmFdKmEpezJ9W15hXSokIjsKCQkKCQlTdHJpbmdbXSBleGVtcGxvcyA9IG5ldyBTdHJpbmdbXSB7IAoJCQkiLS0tYWFiYisrKyIsIi0tLWJiYWErKysiLCItLS1hYmFiKysrIiwiLS0tYmFiYSsrKyIsCgkJCSItLS1iYWJiYSsrIiwiLS0tYmJiYmJhYSIsImFiYWJiYisrKysiLCJjY2FiY2FiKysrIiwKCQkJIi0tLS1iY2RiYWEiLCItYWJhYmQrKysrIiwi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