I am working on some string manipulation using jQuery.
Basically, within a .click(function(){ I have the following string variable:
f?p=251:1007:3642668879504810:::::
What I need to do using jQuery is basically remove the number 3642668879504810 (which changes, i.e is a random number so cannot match on this number) between the second and third colon within this string variable, so the end result would be as follows, still maintaining all the colons
f?p=251:1007::::::
A quick way using split()
:
var str, split_str, new_str;
str = 'f?p=251:1007:3642668879504810:::::';
split_str = str.split(':');
split_str[2] = '';
new_str = split_str.join(':');
// new_str == 'f?p=251:1007::::::'
stringVar = stringVar.replace(/\d+(:+)$/, '$1');
Should work. It finds digits only followed by colons and replaces it with those colons (thereby removing the digits).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With