RegEx Question - Remove everything between : and ~
I am having trouble getting a regex to work. This is the string.
"some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here"
I need to remove the
:39.74908:-104.99482:272~
part of the string. 开发者_如何学PythonI am using jQuery if that helps.
var str = "some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here";
alert(str.replace(/:[^~]+~/g, ""));
var your_string = "some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here";
alert(your_string.replace(/:.+~/, "")); /* some text would be here and Blah StTurn right over here */
You don't need an extremely complex regex for this:
var str = 'Blah St:39.74908:-104.99482:272~Turn right over here';
str.replace(/:.*~/, '');
var string = 'some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here'
var string2 = string.replace(/(?::-?\d+(?:\.\d+)?){3}~/g, '')
Will replace all instances of :number:number:number~
The numbers can be negative and can have decimals
精彩评论