I\'m trying to do some PHP preg. But it seems to i can\'t get it to match if i want a string without something in it.
Example:
Hello! My name is [b]Peter
It's unclear what you want to find. If it's just [b]Peter[/b]
, then you don't need a regex.
If you want to find a single "word" surrounded by BBCode bold tags, use
preg_match('%\[b\]\w*\[/b\]%', $subject)
If you want to find anything within BBCode bold tags as long as it doesn't contain Jack
, use
preg_match(
'%\[b\] # Match [b]
(?: # Try to match...
(?!Jack) # (unless the word "Jack" occurs there)
. # any character
)*? # any number of times, as few as possible
\[/b\] # Match [/b]%x',
$subject)