var string = 'http://blablab/test' string = string.replace(/[\s\S]*\//,'').replace(/[\s\S]*\//,'').replace(/[\s\S]*\//,'') alert(string)
This is a regular expression. I will explain below
Regular expression /[\s\S]*\//
/ is the beginning of a regular expression
If [\s\S] means a space or non-empty space (nothing), you should not be confused with . which does not match line breaks ( . matches the [^\r\n] ).
* means that we match anywhere from zero to an unlimited number [\s\S]
\/ The tool matches the slash character
The last / is the end of the regex
George Bailey
source share