Grandy Grandy - 1 month ago 6
PHP Question

PHP regex any number

I search for patterns like this number+space+number+space+anything

If have this right now:

if( preg_match( '[0-9][ ][0-9][ ].', $searchString ) )

This seems to work ok but fails on the numbers. As far as i can see there should be a selector for "any number". How can i do this in regex.

It should return true for these cases:

0 0 asdf
1 0 asdf
0 30 adsf asdf
22 0 a


[0-9] only accepts the integers 0,1,2,3,4,5,6,7,8,9. For any integer, you need to allow one or more repetitions of [0-9]. If you use the shortcut \d for [0-9] then you can write it as

\d+ \d+ .*

The + symbol means One or more repetitions.

Note: It seems like your new to reg expression. Try out this free regex tutorial.