Regular expression difference

Hello.

I know PHP for a long time, but I seem to know regular expressions, but I don’t understand the syntax itself.
For example, I don’t understand what is different

preg_replace("!jhj(.*?)hg!si","hgfh",$string);

from

preg_replace("/jhj(.*?)hg/si","hgfh",$string);

from

preg_replace("/jhj(.*?)hg/i","hgfh",$string);

Perhaps I’m asking in the wrong place, but I don’t know where they write in detail about reg. expressions.

Thank you.


Answer 1, authority 100%

The last expression does not use the /s (PCRE_DOTALL)modifier, which matches all characters in the template, including newlines. Those. in expression 1 and 2, *matches all characters except for whitespace, and in expression 3, whitespace is included in the set.


Answer 2

Because one uses / and the other uses !

This should not affect the work. Separators are chosen for reasons of readability. Within an expression, the character used as a delimiter must be escaped

Leave a reply

Please enter your comment!
Please enter your name here