Matching "^" through regular expression in preg_match_all
Posted: Thu Apr 02, 2009 3:17 pm
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I want the following code to match strings such as [[^A]], [[^ABC]], [[ABC]], etc. i.e.,strings in double brackets that may have 0 or more ^ in the beginning with alpha characters following. Then return the values in the double brackets, i.e., ^A, ^ABC, ABC.
However, somehow the PHP code below does not work for matching the ^. Where is the error?
Michael.
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I want the following code to match strings such as [[^A]], [[^ABC]], [[ABC]], etc. i.e.,strings in double brackets that may have 0 or more ^ in the beginning with alpha characters following. Then return the values in the double brackets, i.e., ^A, ^ABC, ABC.
However, somehow the PHP code below does not work for matching the ^. Where is the error?
Michael.
Code: Select all
function myData ($text) { //text passed in
preg_match_all("/\[\[(\^*\w+)\]\]/", $text, $matches);
foreach ($matches[1] as $val) {
$text = preg_replace ("/\[\[$val\]\]/",getData($val),$text);
}
return $text;
}pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: