O
O
Optimus2015-09-21 09:02:52
JavaScript
Optimus, 2015-09-21 09:02:52

Replacement in JavaScript?

function loadPage() {
    var buk = "zzxxvvbbzz";
    console.log(buk);
    
    var reg=/zz(.*?)zz/g;
    var after = buk.replace(reg, "");
    
    console.log(after);
   }

It works, removes everything, how to remove only the middle zz xxvvbb zz and leave zz?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Optimus Pian, 2015-09-21
Pyan @marrk2

var after = buk.replace(/(zz)(.*?)(zz)/g, "$1$3");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question