Reputation: 19
I have this URL and I only want to match 4 which can be any number from 0-99.
/img/4.png?t=1351606887
What's the regex to match the number 4 and any other number only?
Upvotes: 0
Views: 1016
Reputation: 44289
This really depends on how flexible your URL can be. Depending on your regex flavor you can either use lookarounds:
(?<=/img/)\d+(?=\.png)
Or a capturing group:
/img/(\d+)\.png
In the latter case you will match /img/4.png
but the first captured group will contain only the 4
.
Which variant you can use, and how to retrieve the capture content really depends on your language/tool.
Upvotes: 1