Jump to content


Photo

Regex


  • Please log in to reply
6 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 14 June 2006 - 12:16 AM

Why doesn't
/<OL><LI>.[^<\/LI>]*<\/LI>/s

match

<OL><LI><OL TYPE="a"><LI TYPE="a">text.</LI>

Wouldn't . include <OL TYPE="a"><LI TYPE="a">

Also, if I wanted to make it single line and case insensitive, what would I do? Would it just be /regex/si?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 12:32 AM

It won't match that because of the negated characters. Something like this:

/<OL><LI>(.*?)<\/LI>/s

Would make more sense. For case insensitive matching, use the PCRE_CASELESS modifier (i). For single line only, remove the PCRE_DOTALL modifier (s).

/<OL><LI>(.*?)<\/LI>/i

~ D Kuang

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 14 June 2006 - 01:09 AM

So what exactly was wrong with my regex. I thought it said "match any characters (except for a bullet end), until you find a bullet end."

And what if I wanted it to not stop at \n (/regex/s) AND be case insensitive (/regex/i)? How would I combine them?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 01:24 AM

It says "match any characters except <, /, L, I and >". As it is in a character class, each character is considered independent.

Simply use /pattern/si
It doesn't matter the order (so it could be /pattern/is); everything outside the delimiter is considered a pattern modifier.
~ D Kuang

#5 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 15 June 2006 - 05:58 PM

More regex - why isn't
/<DL><DD>(.*?)<\/DD>/si
matching
<I>text.</I> <DL><DD>text.</DD></DL><HR ALIGN="LEFT" .....
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 15 June 2006 - 06:51 PM

It does.

<?php
    $string = '<I>text.</I> <DL><DD>text.</DD></DL><HR ALIGN="LEFT"';
    if (preg_match('/<DL><DD>(.*?)<\/DD>/si', $string)) {
        print 'matched';
    }
?>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 15 June 2006 - 07:09 PM

Oh man my fault. I just realized I used strip_tags() to strip everything but <ol> and <li>. Thanks alot.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users