Using NOT

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
yoda69
Forum Newbie
Posts: 16
Joined: Wed Jun 20, 2007 10:21 am

Using NOT

Post 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,
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using NOT

Post 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
fwycruiser118
Forum Newbie
Posts: 9
Joined: Sat Oct 09, 2010 7:45 pm
Location: Calif

Re: Using NOT

Post 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];
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Using NOT

Post 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.
Goldwinterrain
Forum Newbie
Posts: 4
Joined: Sun Mar 13, 2011 9:15 pm

Re: Using NOT

Post 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,
Post Reply