homepage Welcome to WebmasterWorld Guest from 23.20.34.25
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RegEx Matching Multiple Occurrences
NoLimits




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

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 \((.+?)\)/';
preg_match($regex,$data,$match);

Thank you in advance for your time and help.

 

NoLimits




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

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.

NoLimits




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved