Hi I’m new to regex and can’t find a proper solution for this:
I want to cut off the last parameters of the url between the two slashes “/1032/” form url “http://www.blablabla.com/test.php/addpage/1032/”
That i have just http://www.blablabla.com/test.php/addpage/ …though this part is not important of being matched…so just cut off the parameters between the last slashes…
What i did was:
curr_url= "http://www.blablabla.com/test.php/addpage/1032/";
expression =/.*\/./;
alert(expression.exec(curr_url));
Result is “http://www.blablabla.com/test.php/addpage/1”
Now i could cut off the last parameter by a slice but thats not reasonable i guess
Any better solutions? Thanks a lot!
[“http://www.blablabla.com/test.php/addpage/1032/”, “/1032/”]
First greedy
.+captures everything to last slash and then backs off to next-to-last, because rest of pattern would fail otherwise. () capture everything between this slash and last an then\/$at the end tell that string should end after last slash. Move slashes outside brackets if you only want number itself.It seems though I misinterpreted your intent. If you need first part of string, you can use regexp suggested bellow with a little change:
It captures “everything until slash, and then some more”. It will first reach last slash in string, but then back off to previous slash, because there’s not “then some more”, thus leaving exactly the part of string you want.