Jump to content

Recommended Posts

Jazzman: [^\n] matches everything that's not a newline character, exactly the opposite of what GD77 wanted.

 

GD77: Remove the caret from the newline character group, and it should match as you want it to. Here's it a bit cleaned up, and properly escaped for PHP strings too:

'#^[a-z0-9_/a+ -]+<li>(.*?)</li>[\\n\\r]+\\z#i'

Doing this cleanup I found another problem too, namely the fact that you've added the LI tag patter inside the character group. Which caused it to consider the individual characters as part of a group, not as a pattern you wanted matched. I've moved it outside for you, but without any example data I cannot know if this pattern matches what you want.

 

BTW: What's the escaped space after the closing LI-tag?

Edited by Christian F.

Ah, my apology. You want to match new lines :happy-04:

$pattern = '/^[\n\r]?[a-z0-9_\/a\-\<li\>(.*?)<\/li\>\ ]+/i';
if(preg_match($pattern, $va1)){
echo 'true';
} else {
echo 'false';
}

 

@Christian, you pattern won't work, why are you using [\\n\\r] ?

Edited by jazzman1

Unfortunately, the code posted by Jazzman only seems to be working. It has the same issues that I highlighted for your code, due to the grouping of the li-tags inside the square brackets. For all intents and purposes, this is exactly the same:

'#^[\\n\\r]?[\\w?./<>() *-]+#i'

Note that neither period, asterisk, question marks or parenthesis has any special meaning within a character group.

 

Now, if you want help to making something that actually matches what you want it to match, you need to post an example of the source data. As I requested above.

In that case I recommend using something like this:

$RegExp = '#((?:[\\w\\r\\n/ -]|<li>.*?</li>)+)#is';

 

This will grab the entire text in your example, and only if you have a balanced pair of li-tags (or none at all).

Edited by Christian F.
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.