M
M
Maxim Osadchy2017-10-05 19:19:31
JavaScript
Maxim Osadchy, 2017-10-05 19:19:31

How to replace only part of a string found by reg. expression?

https://regex101.com/r/BZGwi8/1
is to replace ib.
But how to replace only part of the result found by the regular expression?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2017-10-05
@waspmax1

var str = "https://days.pravoslavie.ru/jpg/is847.jpg";
var regex = /(is)+([0-9]{1,})+([.])+([a-zA-Z]{2,})/;
console.log(str.replace(regex,str.match(regex)[0].replace(/is/,"ib")));
//https://days.pravoslavie.ru/jpg/ib847.jpg

4
4iloveg, 2017-10-05
@4iloveg

https://regex101.com/r/BZGwi8/2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question