RegEx Question - remove everything between: and ~

I find it hard to work with regex. This is a string.

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

I need to remove

:39.74908:-104.99482:272~

part of the string. I am using jQuery if this helps.

+3
source share
4 answers
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 */
+3
source
var str = "some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here";
alert(str.replace(/:[^~]+~/g, ""));
+4
source
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, '')

All instances will be replaced: number: number: number ~

Numbers can be negative and have decimal numbers

0
source

You do not need an extremely complex regular expression for this:

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

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

Source: https://habr.com/ru/post/1767573/


All Articles