Page 1 of 1

Take anything, but absolutely not one phrase

Posted: Sun Jun 19, 2005 6:00 pm
by Todd_Z
in a preg_match_all I have a (.*?), I want it to take all characters, however, I want it to absolutely stop no matter what at "Employer" is there something like [^"Employer"]*?

Posted: Sun Jun 19, 2005 6:04 pm
by John Cartwright
Moved to Regex.

Posted: Sun Jun 19, 2005 6:10 pm
by nielsene
I'm thinking about it, but I haven't found a good way yet. My reference book is at work....

However can you explain a little more about the problem. It seems like you could do something with strpos to check for "Employer" first.

Or if you know that Employer will always be present and you want to grab everything before it, just do "\(.*)?Employer(.*)?\" to match everything before and everything after, excluding the "Employer" text...

Do either of these ideas fit your needs?

Posted: Sun Jun 19, 2005 6:47 pm
by Chris Corbyn
You could mean this is more than one way. Do you mean you want EVERYTING up UNTIL the word "employer" or do you mean you want EVERYTING EXCEPT the word exployer. Two different regex (one's a replace and one's a match).

Code: Select all

//Up util
preg_match('/^(.*?)(?:Employer)?.*$/is', $string, $matches);
$extract = $matches[1];

//Everything except... bah, I'm not even gonna write it... str_replace() would even do it!
;)

Posted: Sun Jun 19, 2005 6:53 pm
by Burrito
what is the colon doing there d11?

Code: Select all

(?:Employer)
that colon just before Employer...what does that do?

Posted: Sun Jun 19, 2005 8:26 pm
by Skara
the ?: makes the () not return a value.