Renlok Posted June 29, 2009 Share Posted June 29, 2009 well if i input a string which contains {TEST(0)} for example i wont it so the TEST is \\1 and the 0 is \\2 in the replace string ive tried this with this expression but it doesnt work and im not sure why '#\{([a-z0-9\-_]+[\(0-9\)]+)\}#is' thanks in advance for any help Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted June 29, 2009 Share Posted June 29, 2009 One suggestion could be: $str = '{TEST(0)}'; preg_match('#{([a-z0-9_-]+)\(([0-9]+)\)}#i', $str, $matches); // $matches[1] a.k.a = TEST // $matches[2] a.k.a = 0 Note that in your pattern, you can put the dash that you have in the first character class as first or last listed and thus won't need escaping. Also note some issues with your second half of the pattern. You are using a character class to look for either a ( [which inside a character class doesn't need escaping], or 0-9+ or a closing ). Note that all characters inside [..] only checks for a single character, not a sequence of characters. EDIT - also note that the s modifier in your example won't do anything, as that only applies to the dot_match_all wildcard character in conjunction with it matching newlines. Quote Link to comment Share on other sites More sharing options...
Renlok Posted June 29, 2009 Author Share Posted June 29, 2009 oh right ok thanks regex is so confusing. your solution works perfectly. 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.