How do you comment * / part of regex in PHP

I have a preg_replace function that I call and add a few lines to read, but the characters */in regex ruined the comments. How can I comment on all these lines without moving them all to one line?

return preg_replace('/.*/',
    'Lorem Ipsum' .
    'More Lorem Ipsum'
    ,
    $foo);
+5
source share
1 answer

You can use another regex markup character:

return preg_replace('#.*#',
    'Lorem Ipsum' .
    'More Lorem Ipsum'
    ,
    $foo);

EDIT: The delimiter character is a feature of PCRE (Perl Compatible Regular Expresssion). PHP configuration is not required to use a different delimiter.

Regexp query-like operators

... -- . "/", LTS ( ).

, ASCII (, , , )

:

'/.*/'
'#.*#'
'{.*}' /* Note that '{.*{' would be incorrect. */

PHP PCRE Patterns, .

+9

All Articles