2010-10-01 97 views

回答

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

這很好,謝謝chigley – jhanifen 2010-10-01 16:40:56

+2

你可能會考慮製作「。+」lazy - 'string.replace(/:.+?〜/,「」)''。這樣,如果字符串中有更多文本,可能包含波浪號,則不會被消耗。 – 2010-10-01 16:44:44

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

將取代所有實例:數量:數量:數量〜

的數字可以是負的,可以有小數

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

我會用這個。似乎會更安全一些。 – user113716 2010-10-01 16:45:32

0

你並不需要一個極其複雜正則表達式爲:

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

str.replace(/:.*~/, ''); 
相關問題