msaspence Posted November 26, 2007 Share Posted November 26, 2007 i need to pull some segments out of a file (loaded into a variable) the segments i need to pull out is basically anything in brackets what makes its esp hard is the brackets are not your standard () [] or {}, the closing bracket character is in fact two characters for example from the string: £a£b£c!£d!£e!£ f £g!£ where £ equates to ( and !£ equates to ) i want to extract £a£b£c!£d!£e!£ and £g!£ as matches so far i have got to: $string = " §b§c;§d;§"; if(preg_match_all("/(?<!§([^()]+|(?R))*(?<=§/U",$string,$matches)) { echo "<pre>"; print_r($matches[0]); echo "</pre>"; } which returns Array ( [0] => £a£b£c!£ [1] => £g!£ ) the first match is missing the d and e parts Any clues on a solution would be really appreciated Quote Link to comment Share on other sites More sharing options...
effigy Posted November 27, 2007 Share Posted November 27, 2007 I'm not sure why you're using section marks or semicolons, but here is an example: <pre> <?php $string = '£a£b£c!£d!£e!£ f £g!£'; preg_match_all('/£ (?: (?>[^!£]+) | (?R) )* !£/x', $string, $matches); print_r($matches); ?> </pre> yields: Array ( [0] => Array ( [0] => £a£b£c!£d!£e!£ [1] => £g!£ ) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.