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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -