Search code examples
phpregexpathtext-extractiontext-parsing

Match 3 subdirectory names in a filepath string after a specified directory name


/any_string/any_string/any_number

with this regular expression:

/(\w+).(\w+).(\d+)/

It works, but I need this url:

/specific_string/any_string/any_string/any_number

And I don't know how to get it.


Solution

  • /(specific_string).(\w+).(\w+).(\d+)/

    Though note that the .s in your regular expression technically match any character and not just the /

    /(specific_string)\/(\w+)\/(\w+)\/(\d+)/

    This will have it match only slashes.