Skip to content
WJunction - Webmaster Forum

[PHP] Regex find word

Status
Not open for further replies.

skinner

Experienced Member
741
2010
59
Hi,

I'm trying to make a function that find a specif word in a string.

For example:

I need to find WORD

string could be:

- Find this word in this string

or

- Find.this.word.in.this.string

or

-Find-this-word-in-this-string

find 1 text with regex is simple:

Code:
\bword\b

I have problem to find word in the other two example.

Also, how can I return in fuction that I found that string?

Thanks
 

4 comments

\b is a word boundary, meaning the start or end of a line (^|$), or the point at which a sequence of word characters reaches a non-word character (e.g. "x.").

Your pattern works fine for all 3 examples you mentioned. Whats the problem?
 
\b is a word boundary, meaning the start or end of a line (^|$), or the point at which a sequence of word characters reaches a non-word character (e.g. "x.").

Your pattern works fine for all 3 examples you mentioned. Whats the problem?

Yes, it works.

The problem is that I found that I need to find WORD also in this example:

- findthisworldinthisstring

and \bword\b it seems that doesn't work..
 
Status
Not open for further replies.

About the author

S
Experienced Member · Joined
741
Messages
59
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom