Posts Tagged ‘Regular Expressions’

How to extract id/numbers from the end of an URL using Javascript Regular Expressions (Regex)

Wednesday, February 11th, 2009

I was working with the Zend Framework and flowplayer and I needed to extract the ID from the url.
Here is the short JavaScript snippet.

var extr_id_regex = new RegExp('(\\d+)$', "gi");
var url = '/a/b/c/123';
var id = url.match(extr_id_regex);

if (id) {
alert(id);
}

Related