Jump to content

Regex


johnnyk

Recommended Posts

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?
Link to comment
Share on other sites

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

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

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

[code]/<OL><LI>(.*?)<\/LI>/i[/code]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.