How to write a PHP Regex to match string
I only knows basic regex, so I am look for help here.
I need to match URL with this pattern:
/kb/This-is-开发者_开发知识库possible-title-12345.html
The URL will always ends with -nnnnn.html. Currently I have this regex pattern:
'kb/[a-zA-Z_-]*(\d+)\.html'
however, this does not work if the portion contains numbers, such as
/kb/This-is-12345-possible-title-12345.html
This needs to be done with PHP preg_match function.
The following works for me: /kb/[\w_-]*-(\d+)\.html$
.
At a quick glance what you have looks right but you need to escape the forward slash so change '/' to '\/'.
'/kb/[^/]*-\d{5}\.html'
This matches "/kb/" "any characters except '/'" "hyphen" "5 digits" ".html"
精彩评论