Re: Regex question
| From: | Stefan Rusterholz | Date: | Wed, 09 Jan 2002 15:51:02 +0000 |
| Subject: | Re: Regex question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-79915@lists.php.net to get a copy of this message | ||
> > If you want the [ to be escaped in the regex you have to "double-escape"
> it:
> > $x = "\ \["; (sorry, the two \ should be together without a space but my
> > stupid mail-app converts the string thinking it's an network address)
> > so $x will contain "\[" as you want ( the first backslash escapes the
> > second).
>
> Hi Stefan,
>
> Thanks very much for that, it does make sense :-)
>
> Unfortunately it still hasn't fixed the problem... I suppose my question
has
> now boiled down to "do I need to escape !, <, or - in a regex?" :-)
>
> Cheers
> Jon
here the expression again:
>>>$tags = array ("script",
>>> "<!--<!\[CDATA\[",
>>> "\]\]>-->");
>>>foreach ($tags as $currentTag)
>>> if (preg_match ("/^<\/". $currentTag. "/", $content))
>>> // do something
As far as I can see (notice: I'm not a regex-king ;) the regex seems correct
to me. The only thing I'm wondering about is the "/^<" (second last line of
the citation). Together with your expression in the array it results in
preg_match("/<\/<!\[CDATA\[/", ...)
I'm wondering if that (</<![CDATA...) is really what you want to match (and
not only <![CDATA without the trailing </).
If it's not that then I suggest you to do simple example scripts where you
have none-dynamic regex's to test if the expression works (that's the way I
do that stuff - no really because I ever think I'd THIS TIME be able to do
it without, but I haven't thought right till today ;)
lot of luck mastering your expressions
stefan rusterholz