update regex to find ID's just in the last segment of the url
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We have this regex today https://regex101.com/r/vEHFi9/2 It works pretty well but you can see it fails some urls in the middle of the samples




It should be looking only in the last segment for an ID. 2 of the 3 examples here should have no id and the first one should have an id of 2313521

Ideally your update will properly make the story_id only select from the last segment of the url string. As you will also notice some of the last segments dont have a trailing / and just immediately in to params so we have to be sure this update doesnt get tripped up by that.

awarded to Wuddrum

Crowdsource coding tasks.

1 Solution

Winning solution

Hey Qdev, how's this? https://regex101.com/r/01hhrr/1

Added (?:[^\d\/]) before the id check, so it excludes any ID's that start with a / or more numbers (in cases when the number is longer than specified {4,9}).
Wuddrum 4 months ago
as always - thanks!
Qdev 4 months ago