Reputation: 3011
what I'm trying to do is:
www.test.de/testA/testB/testC/cutoff/testD/testE
I need to cutoff the string right after "cutoff". The link will change quiet often, so I need do to something like:
regexp = /cutoff/i (everything which comes after this) window.location = regexp;
The link does also change at the beginning, therefore it is not possible to count the char and replace it then.
Thank you for any answer given to this.
Upvotes: 0
Views: 378
Reputation: 1533
Try
var reg = new RegExp( "([.\/]*\/" + cutoff + "\/)." , 'i' );
window.location = window.location.replace( reg , "$1" );
Upvotes: 0
Reputation: 21071
Is this too simple a solution?
var s = "www.test.de/testA/testB/testC/cutoff/testD/testE"
var re = /(.+cutoff)/i
s.replace(re, "")
Upvotes: 0
Reputation: 8771
Everything up until cutoff/?
/.*cutoff\//
Edit: Here's the JS
var s = 'www.test.de/testA/testB/testC/cutoff/testD/testE';
var x = s.replace(/(.*cutoff\/).*/, '$1');
window.location = x;
Upvotes: 1