0

I have problem with regex.

My string: "[312ds31spacer13d][TestWord]"

In PHP I'm using:

preg_replace('#\[(.*)spacer(.*)]# ', '', $myString);

And this removed the entire string. How to leave "[TestWord]"?

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • Just make thsearch not greedy: `preg_replace('#\[.*?spacer.*?]# ', '', $myString);` – Toto Jan 12 '20 at 15:50
  • Thanks man, you won: D Today I started learn about regex, so maybe for you it is easy problem but for me is hard at start. – Dawid Grzywniak Jan 12 '20 at 15:58
  • You'll find usefull informations [here](https://stackoverflow.com/a/2759417/372239) and [here](https://www.regular-expressions.info/) – Toto Jan 13 '20 at 08:40

0 Answers0