java - Regular expression not matching on first and last word of string -


i trying write java program specific words in string. have working part doesnt seem match if word match first or last word in string. here example:

"trying find first word".matches(".*[^a-z]find[^a-z].*") //returns true "trying find first word".matches(".*[^a-z]trying[^a-z].*") //returns false "trying find first word".matches(".*[^a-z]word[^a-z].*") //returns false 

any idea how make match on word in string?

thanks in advance,

craig

the problem character class before , after words [^a-z]- think want word boundary character \b (as per colind's comment) opposed not character in a-z range. pointed out in comments (thanks) you'll needs handle start , end of string cases.

so try, eg:

"(?:^|.*\b)trying(?:\b.*|$)"  

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -