1

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

1
  • Is there any particular reason why you are using look ahead? Normally /(\w+)\((\w+)\)/ would suffice. Commented Apr 28, 2010 at 10:40

1 Answer 1

4
'/\w*(?=(?:\((.*)\))?)/'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.