Reputation: 3
Trying to find words between . and =, which are uppercase (optional and contain underscore between them) like UPPER_CASE
String myString = "test.UPPER_CASE=#123456"; //Should pass
if(myString.matches(".*\\.[A-Z]=")) {
System.out.println("Match");
} else {
System.out.println("No Match");
}
Upvotes: 0
Views: 122
Reputation: 51330
You were really close, you just forgot to match the underscore and add the quantifier:
\.[A-Z_]+=
To use it from Java you can do this:
myString.matches(".*?\\.[A-Z_]+=.*")
That's the same pattern with .*?
at the beginning and .*
at the end, because the matches
function requires the pattern to match the whole input string. I guess there's a better API available to get a substring match, but I don't use Java myself.
Upvotes: 1