voku / Stringy

:accept: Stringy - A PHP string manipulation library with multibyte support, performance optimized
MIT License
171 stars 19 forks source link

Stringy::regexReplace(): trouble with pattern containing a / character #9

Closed kije closed 7 years ago

kije commented 7 years ago

I run in an issue with the Stringy::regexReplace() method. I need to pass in a pattern with a "/" character in it. But this leads to an error, since the preg_replace() call inside regexReplace() uses the / as the delimiter for the regex pattern.

The easiest solution would be to add a 4th parameter to Stringy::regexReplace() which allows to specify a custom regex delimiter.

voku commented 7 years ago
  1. you can use "preg_quote($foobar, '/')" to escape the '/'-char in the pattern
  2. I added the 4th parameter to Stringy::regexReplace() [in version 2.2.36] -> https://github.com/voku/Stringy/commit/41b5a7c63a49f9c8180d53bca66dd5c16aa0e515#diff-72c90db4478e945428a2eb3bcc72971dR319