RegEx问题 - 删除:和〜之间的所有内容

时间:2010-10-01 16:34:49

标签: javascript regex

我无法让正则表达式工作。这是字符串。

"some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here"

我需要删除

:39.74908:-104.99482:272~

字符串的一部分。如果有帮助,我正在使用jQuery。

4 个答案:

答案 0 :(得分:4)

var str = "some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here";
alert(str.replace(/:[^~]+~/g, ""));

答案 1 :(得分:3)

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 */

答案 2 :(得分:0)

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, '')

将替换所有实例:number:number:number~

数字可以是负数,可以有小数

答案 3 :(得分:0)

您不需要极其复杂的正则表达式:

var str = 'Blah St:39.74908:-104.99482:272~Turn right over here';

str.replace(/:.*~/, '');