Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg-replace and whole words

Status
Not open for further replies.

elck

Programmer
Apr 19, 2004
176
NL
Hi Folks,
To find whole words I have got this working:
Code:
$pattern[]="/\\b(" . trim($a) . ")\\b/i";
Instead of \\b I also tried \\w and \\W

This nicely captures whole words as expected, but:

I would like to avoid for example [blue]word[/blue] in [red]<word[/red] and [red]word=[/red]
because they could be tags or attributes.
I cannot figure out a pattern that does all that.

[gray](BTW I really need preg_replace even if it takes more processing power)[/gray]

 
can this be done through logic? i.e. a whole word must be
(a) either at the start of the paragraph or preceded by a space AND
(b) must either be followed by a full stop, a comma (or other punctuation) or a space.

 
...a whole word must be
(a) either at the start of the paragraph or preceded by a space AND
(b) must either be followed by a full stop, a comma (or other punctuation) or a space.
or at the end of the paragraph.

Is this too complex?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top