September 22nd, 2009, 06:38 AM
Join Date: Nov 2001
Location: North West UK
Block doesn't contain sequence?
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><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?
9 out of 10 PHP problems can be resolved by setting
php -l <filename> will identify 9 out of the remaining 10 problems
Remember, the command line
is your friend
Last edited by Mark Baker : September 22nd, 2009 at 06:44 AM.