I’m trying to make a simple regex pattern work using java. I need to recognize any uppercase word ending with trailing asterisk with a sentence. From the following example :
Test ABC* array
I need to identify “ABC*” or to be precise, any word with upper-casing ending with an asterisk. I tried the following pattern matching with my limited regex knowledge, but it hasn’t worked out so far.
String text = "Test ABC* array";
Matcher m = Pattern.compile("\b[A-Z]+[*]?\b").matcher(text);
Any pointers will be appreciated.
Thanks
the problem is that you don’t have a word boundary at the end after the star. So try this
\Bis not a word boundary, so this is exactly what you get between the*and a whitespace.See it here on Regexr