Search code examples
phpregexregular-language

Regular Expression of a particular String in PHP


I have this few strings:

'user/1/myid_print'
'user/2/myid_print'
'user/3/myid_print'
'user/4/myid_print'
'user/5/myid_print'

The second part is the dynamic one which must contain only integers. What is it's regular expression?


Solution

  • Try this:

    /user\/\d+\/myid_print/
    

    the \d+ matches a number which contains at least one digit. if it is a non-zero number, replace the \d+ with [1-9]\d*