Jump to content

[SOLVED] Block not containing sequence?


Mark Baker

Recommended Posts

I'm trying to extract a list of "entries" from between pairs of tags in a string, where the entries don't contain a particular value.

 

The following will return all of entries between the A+ and -A tags, except where the entry contains a numeric 5 among its digits.

$test = '12 A+ 1234 -A 34 A+ 3456 -A 56 A+ 5678 -A 78';

preg_match_all('/A\+([^5]*)\-A/U', $test, $matches, PREG_SET_ORDER);
echo '<pre>';
print_r($matches);
echo '</pre><br />';

So far, so good.

 

However, what I need is for numbers containing a specific sequence of digits to be excluded, rather than just a single digit.

I've tried modifying ([^5]*) to ([^(45)]*) expecting it to return the 1234 and 5678 values, only excluding the 3456 value; but instead it returns nothing.

 

I'm assuming that the (45) is being ORed: treated as "not containing either 4 or 5". How can I modify the regexp to treat this as a sequence of values rather than a series of options?

 

Any help with what I'm doing wrong?

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.