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
https://forums.phpfreaks.com/topic/175092-solved-block-not-containing-sequence/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.