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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -