Doubt with regular expression, data from a url

Asked

Viewed 36 times

0

I have these Urls

veiculos-sao-paulo-__4--6--.html
veiculos-parana__4--6--.html
veiculos-rio-de-janeiro-__4--6--.html

With this regular expression:

^veiculos-([a-zA-Z-]+)__.+\.html?

Caught the group $1 with the following outputs:

sao paulo-

Parana

rio de Janeiro-

I wish I didn’t get the "-" hyphen at the end.

How could I adapt mine regex not to capture the hyphen, whereas it may or may not come at the end of the url?

intended exit:

sao paulo

Parana

rio de Janeiro

  • With exactly the same regex, but hyphenate after the group you want to capture: ^veiculos-([a-zA-Z-]+)-__.+\.html?

1 answer

0


  • Thanks Pedro. Perfect

Browser other questions tagged

You are not signed in. Login or sign up in order to post.