tags:

views:

42

answers:

1

I have the simple regular expression:

\{[0-9]*\}

which works fine with PHP's ereg_ functions (Posix compatible), but I need to use the preg_match_all function, which doesn't have an ereg_ equivalent. My expression above doesn't seem to work with preg_ (perl compatible) functions. How can I go about "converting" it to be perl compatible?

+1  A: 

If im reading your regex correctly then just do this:

preg_match_all('/\{\d*?\}/'...);

'/\{\d*?\}/' will match an integer of any length.

Unkwntech
I need any length of integer inside {} braces - sorry about that.
Shadow
I edited to reflect that
Unkwntech
It looks like you're only matching a single digit. To match the original posix regex, I believe you'd want /\{\d*\}/
EvanK
\d matches and integer 1 is valid as is 99999999999999999999999
Unkwntech
Uh, \d is shorthand for digit. It matches a single digit character, not an infinitely long integer. (Unless PHP does something really odd, which I doubt).
Peter Boughton