I have the below code that "kind of" works. $content = "Zs dasd jasjd asjdo asjio [mytag 0970897890,222,11] das jio das idopas s sjiopd sd [mytag 123456,356,66]"; preg_match_all("/\[mytag (.+?)\]/ise", $content,$matches); $X=0; foreach($matches as $var){ echo $var[$X] . "<br>"; $X+=1; } PHP: the output is: [mytag 0970897890,222,11] 123456,356,66 when I just want: 0970897890,222,11 123456,356,66 --------------------------- i know I can use str_replace in my loop to clean the output, however I would like to fix the actual problem with the regular expression.
Try the following code, $content = "Zs dasd jasjd asjdo asjio [mytag 0970897890,222,11] das jio das idopas s sjiopd sd [mytag 123456,356,66]"; preg_match_all("/(0-9\,)/ise", $content,$matches); $X=0; foreach($matches as $var){ echo $var[$X] . "<br>"; $X+=1; } Code (markup): Hopefully that will give you your desired results.