GoneNowBye Posted June 17, 2010 Share Posted June 17, 2010 i'm at school now on my phone btw, so if its obvouse its because my mind is focused on the pending stats exam heres the problem i need a REGEX expression which matches "[this] but not \[this]" my expression : /[^\\]\[[(a-z)]*\]/ its fine, but it wont match correctly if a valid tag ([tag]) is at the start of the string "[hello] \[world]" no matches " [hello] \[world]" matches [hello] please help Quote Link to comment https://forums.phpfreaks.com/topic/205057-ive-got-an-expression-just-needscorrecting/ Share on other sites More sharing options...
GoneNowBye Posted June 17, 2010 Author Share Posted June 17, 2010 i've now got /([^\\])\[[a-z]*\]/ which works, but its returning a multidimension array, i just want the overall matches any thoughts please? Quote Link to comment https://forums.phpfreaks.com/topic/205057-ive-got-an-expression-just-needscorrecting/#findComment-1073410 Share on other sites More sharing options...
GoneNowBye Posted June 17, 2010 Author Share Posted June 17, 2010 /(?:[^\\]|^)\[[a-z]*\]/ works!!! but it returns a multidmensional array, i want the [1] one...can i get rid of the first (memory is a concern serously) Array ( [0] => Array ( [0] => [hello] [1] => [test] ) [1] => Array ( [0] => [hello] [1] => [test] ) ) the first one has a trailing space Quote Link to comment https://forums.phpfreaks.com/topic/205057-ive-got-an-expression-just-needscorrecting/#findComment-1073416 Share on other sites More sharing options...
Psycho Posted June 17, 2010 Share Posted June 17, 2010 The issue has nothing to do with your expression. It has to do with how the PHP function returns matches. I assume you are using preg_match_all(): http://us.php.net/manual/en/function.preg-match-all.php Please read the documentation on how values are populated into the $matches parameter and the available flags to modify the returned values. The default is to Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on I don't believe you can get what you are after, but you can try experimenting with the other flags. Quote Link to comment https://forums.phpfreaks.com/topic/205057-ive-got-an-expression-just-needscorrecting/#findComment-1073517 Share on other sites More sharing options...
GoneNowBye Posted June 18, 2010 Author Share Posted June 18, 2010 thanks very muchly Quote Link to comment https://forums.phpfreaks.com/topic/205057-ive-got-an-expression-just-needscorrecting/#findComment-1073795 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.