Match word with Regex (at the beginning, the end or in the middle) of text -


i wondered if possible using 1 single regex pattern find word in string wherever located.

let's want find word of 6 letters starting capital 'b' , ending lower 'r', sake let's use word 'butter'.

i want match within these sentences:

"butter good" "i love butter" "where butter is?" 

but don't want match these:

"zzzbutter good" "i love zzzbutter" 

using simple pattern this: "/(b[a-z]{4}r)/i" isn't enough...

any idea if possible done in 1 single regex?

you can use regex word boundaries on each side:

/\bb[a-z]{4}r\b/i 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -