jquery - How to find in javascript with regular expression string from url? -


good evening, how can find in javascript regular expression string url address example have url: http://www.odsavacky.cz/blog/wpcproduct/mikronebulizer/ , need string between last slashes (/ /) http://something.cz/something/string/ in example word need mikronebulizer. thank help.

you use regex match group.

use this:

/([\w\-]+)\/$/.exec("http://www.odsavacky.cz/blog/wpcproduct/mikronebulizer/")[1]; 

here's jsfiddle showing in action

this part: ([\w\-]+)

  • means @ least 1 or more of set of alphanumeric, underscore , hyphen , use first match group.

followed /

and the: $

  • which means line should end this

the .exec() returns array first value full match (ie: "mikronebulizer/") , each match group after that.

  • so .exec()[1] returns value: mikronebulizer

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -