S
S
Sergey Valitov2015-10-05 18:10:25
PHP
Sergey Valitov, 2015-10-05 18:10:25

How to replace text in JS using regex?

Hello! There is a line like :qwerty1:qwerty2...
So - I need to replace the text between the colon and the ellipsis (inclusive) with an empty one. That is, remove the text. Apparently with the help of a regular expression .. As a result, you should get something like: qwety1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MK, 2015-10-05
@serejatoje

":qwerty1:qwerty2...".replace(/:[^:]+?(\.{3}|…)/,"")

V
Vitaly Inchin ☢, 2015-10-05
@In4in

Much easier without regular expressions:

var str = ":qwerty1:qwerty2...",
      divided = str.split(":");

divided.pop();
alert(divided.join(":"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question