Featured post
regex - Regular Expressions and JavaScript: Find digits in last part of string -
i need extract id number string. results given me in following format: "something kind of title (id: 300)" "1, 3, 4 - starts numbers (id: 400)" etc..
these values passed javascript, needs extract id number only, i.e. 300, or 400 in above example.
i still struggling regex, appreciated. can string operations, feet wet regex on actual examples can use. online tutorials i've read far have proven fruitless.
thank you
if number in form (id: ###)
\(id: ([0-9]+)\)
should regex. brackets around id , number escaped, otherwise considered matching group (as brackets around [0-9]+
are. [0-9]
means check character between 0 , 9 , +
means 'one or more of'.
var regex = new regexp(/\(id: ([0-9]+)\)/); var test = "some kind of title (id: 3456)"; var match = regex.exec(test); alert('found: ' + match[1]);
example: http://jsfiddle.net/jonathon/fumhr/
http://www.regular-expressions.info/javascript.html useful resource
- Get link
- X
- Other Apps
Comments
Post a Comment