B4J Question Is there a way to search for complete words using RegEx?

Diceman

Active Member
Licensed User
It doesn't appear that B4X's RegEx supports searching for a word boundary like "\<cat\>". This will find the word "cat" as long as it is a complete word, and not part of another word like "catalog" or "blackcat".

An expression of "\<cat" is suppose to find words starting with "cat" like "catalog" and "cat\>" is suppose to find words ending in "cat" like "blackcat".

Example:
Regex.Matcher("\<cat\>", "The cat, named Jinx, liked to get into trouble.")

doesn't return a match.

I can create an expression that parses all of the words including those with punctuation, and then check each word against what I am searching for, but that involves a loop and is a bit CPU intensive.

Is there a way to search for a complete word using RegEx? Keep in mind the text may have punctuation like a comma and that should be construed as a word break.

TIA
 

OliverA

Expert
Licensed User
Longtime User
\b(cat)\b
 
Upvote 0
Top