Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RegEx Matching Multiple Occurrences



4:41 pm on Jun 5, 2009 (gmt 0)

10+ Year Member

After several solid hours of trying to comprehend regular expressions, I have to know the answer.

I am trying to get the data between all occurrences of "Apply for this position (" and the closing parentheses.

The first problem is that it only seems to be trying to find one match.

Second, it is returning an array with the full "Apply for this position (Truck Driver)" as $match[0] and the data I actually want "Truck Driver" as $match[1]

I would prefer to put only the data I need into the array so that it would look like:

$match[0] = Truck Driver
$match[1] = Machine Operator
and so on

My code is below, I have tried adding the g modifier, as well as preg_match_all to resolve the single match problem to no avail. I get an error stating unknown modifier g.

$regex = '/Apply for this position \((.+?)\)/';

Thank you in advance for your time and help.


5:31 pm on Jun 5, 2009 (gmt 0)

10+ Year Member

I have made some additional progress.

$regex = '/Apply for this position \((.+?)\)/ism';

The above is returning multiple matches, but the first half of the array is filled up with "Apply for this position (Truck Driver)" when all I really need is the "Truck Driver" piece.


8:13 pm on Jun 5, 2009 (gmt 0)

10+ Year Member

Last update, I promise...

$regex2 = '/Apply for this position \((.+?)\)/';
preg_match_all($regex2, $data, $match);
foreach ($match[1] as $item) {
print "$item<br />";

Resolved, but perhaps there is a better approach that someone may suggest.


Featured Threads

Hot Threads This Week

Hot Threads This Month