Re: Is there a faster way to escape special characters in a regex?
| From: | Andrey Hristov | Date: | Tue, 12 Mar 2002 14:30:53 +0000 |
| Subject: | Re: Is there a faster way to escape special characters in a regex? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-88200@lists.php.net to get a copy of this message | ||
Yes they are identical. The rule is that the first and the last(excluding modificators) symbol must
be identical so
|abc|
~abc~
/abc/
%abc%(not sure for that)
are equivalent. The docs uses // syntax because it is the most popular.
Regards,
Andrey Hristov
----- Original Message -----
From: "Richard Davey" <rich@fatal-design.com>
To: <php-general@lists.php.net>
Sent: Tuesday, March 12, 2002 4:26 PM
Subject: Re: [PHP] Is there a faster way to escape special characters in a regex?
> "Andrey Hristov" <ahristov@icygen.com> wrote in message
> news:053801c1c9d0$5b4da400$0b01a8c0@ANDreY...
>
> > In PHP 4.0.5 and later, every parameter to str_replace() can be an
> array.If search and
>
> Thank you for pointing that out :)
>
> I've now changed my code from the (rather lengthy) version to the following
> which worked perfectly for me:
>
> $regcheck =
> array("/","\\","^",".","[","]","$","(",")","*","?","{","}");
> $regreplace =
>
> array("","","\^","\.","\[","\]","\$","\(","\)","\*","\?","\{","\}");
> $badwordtest = "/" . str_replace($regcheck,$regreplace,$badwords[$i]) .
> "/i";
>
> > BTW /abc/ and ~abc~ are equivalent regexes. So get a character which will
> not occur in the string and put in the front and the end.
>
> Does this mean that ~myword~ and /myword/ are identical?
> I only used /myword/ because it's in the php manual example like that.
>
> Cheers,
>
> Rich
> --
> Fatal Design
> http://www.fatal-design.com
> Atari / DarkBASIC / Coding / Since 1995
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>