Page 1 of 1
Using NOT
Posted: Wed Dec 22, 2010 7:06 pm
by yoda69
Hey,
Here's a string
<b>Location:</b> Your computer<br />
I want my regex to catch everything EXCEPT "<b>Location:</b>"
I remember the ^ symbol is used to express NOT but i'm spending too much time in figuring out how to make it work.
Let me know if you have a quick answer for me,
Thanks,
Re: Using NOT
Posted: Wed Dec 22, 2010 10:54 pm
by Jonah Bron
Is that the whole string? Because you could just use substr()
Code: Select all
$string = '<b>Location:</b> Your computer';
$location = substr($string, 17);
http://php.net/substr
Re: Using NOT
Posted: Sat Jan 22, 2011 10:04 pm
by fwycruiser118
previous example is probably the best move but you might like this too
$subject = '<b>Location:</b>Your computer';
$pattern = "/^<b>Location:<\/b>(.*)/i";
preg_match_all($pattern, $subject, $matches);
print_r($matches);
echo $matches[1][0];
Re: Using NOT
Posted: Sat Jan 22, 2011 10:18 pm
by josh
I'd probably use
http://php.net/strip_tags and then that way I don't have to put HTML tags in my regex, more clean. As shown the ^ (caret) is the "not" symbol in regex.
Re: Using NOT
Posted: Mon Mar 14, 2011 12:38 am
by Goldwinterrain
I remember the ^ symbol is used to express NOT but i'm spending too much time in figuring out how to make it work.
Let me know if you have a quick answer for me,