PHP preg_match to get function-like string

Posted by pistacchio on Stack Overflow See other posts from Stack Overflow or by pistacchio
Published on 2010-04-28T10:31:44Z Indexed on 2010/04/28 10:33 UTC
Read the original article Hit count: 199

Filed under:
|

Hi to all,

if I have a string like 'foo(bar)', with the following code i can almost parse it the way i want:

$results = array();
preg_match( "/\w*(?=(\(.*\))?)/", 'foo(bar)', &$results );
print_r($results);

/*    
Array
(
    [0] => foo
    [1] => (bar)
)
*/

How can I modify the regex to have bar instead of (bar)? Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about regex