-1

I need an regex that match

"my dog", "My dog", "my &dog"

but not

"my dog#", "My dog#"

for search string "my dog". I have this expression at the moment by I have this:

reg_replace("/\b(my dog)\b/ui",'found','My dog');

But this obviously matches "my dog#" and not "My &dog". Any help would be appreciated.

mephisto73
  • 98
  • 7

1 Answers1

-2

my..?dog$

. = any Space .? = 0 or 1 of any Space

$ = end of string

As not casesensitive this doesnt matter. If you only have these, you can make a ".?" to get this one Dog with "&" with end of string, you can simply get these other dogs you dont want out there.

Tested with regex101, if only these values are there, this is enough. Flags = gsmi (Global, Multiline, singleline, insensitive)

Daniel H
  • 21
  • 3