tags:

views:

50

answers:

2

Hi, I have a string Like this:

MyText (1,151)

I would like to get with regex only the value inside (), in this case only: 1,151.

I know it is simple but I am not good with regex.

Thanks!

+3  A: 

This will work:

if (preg_match($str, '/\(([^)]*)\)/', $matches))
{
    $content = $matches[1];
}
Nat Ryall
+1 beaten by 3 seconds :)
soulmerge
+6  A: 

A nearly identical question was just asked. There are solutions in there that will work for you ;)

Peter Bailey
I'd recommend taking a look at the question linked, too. Using a regular expression for something so trivial is usually overkill.
Andy E