I have data in format:
Randomtext1 (random2,random4) Randomtext2 (ran dom) Randomtext3 Randomtext4 (random5,random7,random8)
So I would like to recognize the both the Randomtext-part and the text with in brackets, if it is there with preg_match_all, but im not sure how to get it done. The stuff in the brackets goes together with the Randomtext-part and some of the Randomtext-parts have it and some of them dont.
This is what I have so far, and it works in most cases, but if the text doesnt have any brackets, then it matches the whole thing to one.
preg_match_all("/([a-zA-Z]+)\s+(?([a-zA-Z, ]*))?/",$text,$matches);
Any ideas?