The regular expression would be something like this: (.*?) \([^)]*\),?
It uses . (anything) because you requested so, but if it's a word you should use \w instead, or if it's anything but whitespace \S so it would be something like this: (\S*) \([^)]*\),?
Explaining the expression:
(.*?)
- match anything, but in lazy mode, or 'as little as possible'
mode
[^)]*
- match anything but ) as many as possible
\([^)]*\)
-
match a pair of brackets and it's content
,?
- match a comma if it's
there
You can test it all these HERE
Finally, using the preg_match_all
PHP function, this would look something like this:
$str = 'something (this1), something2 (this2), something3 (this3)';
preg_match_all('/(\S*) \([^)]*\),?/', $str, $matches);
print_r($matches);