user311509
user311509

Reputation: 2866

Grab Values between Slashes using Regex

http://example.com/...../post/index/88/mike-hey-dddd

I need to grab the ##

index/##/

"##" denotes numeric value.

I'm planning to run the regex is javascript.

Upvotes: 0

Views: 150

Answers (1)

Roonaan
Roonaan

Reputation: 1066

You can use the \/ to escape slashes you want to use in your regular expressions:

So the result would be:

var input = "http://example.com/...../post/index/88/mike-hey-dddd";

var match = input.match(/\/index\/(\d+)/i);

// Make sure to validate the result, as it might not
// match for a given alternative url.
var number = match ? match[1] : false;

alert(number);

Upvotes: 1

Related Questions