Java regex pattern matching for word ending with asterix literal
java, regex
Solution
the problem is that you don't have a word boundary at the end after the star. So try this
Matcher m = Pattern.compile("\\b[A-Z]+\\*\\B").matcher(text);
`\B` is not a word boundary, so this is exactly what you get between the `*` and a whitespace.
See it here on Regexr
Problem
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