I need to retrieve certain portion of an url using regex. The url looks like this:
/xxxx/bbbb/good/city/games_in_the_city.~cccccc~dddddd~eeeee.html
I need to retrieve games_in_the_city. I got the first portion until the / removed. Now need to find the first occurence of ~ in the string so that the rest can be removed as well.
The regex that I have right now (.*\/good\/city\/)(.*)(\.html) gets games_in_the_city.~cccccc~dddddd~eeeee
How can I modify my regex so ~cccccc~dddddd~eeeee can be removed as well. The final output should be games_in_the_city
I will not know how many ~ (tilde) can appear in the url. sometimes it might one to n.
You can use the regex:
See it