开发者

RegEx Question - Remove everything between : and ~

开发者 https://www.devze.com 2023-01-18 21:44 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号