Regex that matches when item is mid-string or end string -


using regex in iis url rewrite (microsoft)

i trying write regex capture companyname/company-name in of following:

get-involved/companies/company-name-2

get-involved/companies/company-name

get-involved/companies/companyname-5

get-involved/companies/companyname

so clear want capture variable companyname may or may not have trailing -[0-9] dont want trailing -[0-9]

i have following not right includes -2 when present

get-involved/companies/((.*)|((.*)(-[0-9]))) 

this answer work js or php, noticed @tom zych, little specifications may different iis url rewrite, don't use: it's check.

that's said, can use followin regexp:

^get-involved/companies/([^-]*)-?([^-]*)?(?:-[0-9])$ 

then use following replacement:
$1$2


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -