OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Replace multiple values in text using REGEXP JS [duplicate]

  • Thread starter Thread starter Cove
  • Start date Start date
C

Cove

Guest
i have some text in str which i have to delete using regexp mask. It works fine for the first time but another search value doesn't replace. But why?

Code:
const reg = /(^\d{1,2})\s(may)\s(\d{4})/
var str = `22 may 2024 ac 22 may 2024`
for (i=0; i<2;i++){
var newStr = str.replace(reg, "");}
console.log(newStr);

<p>i have some text in str which i have to delete using regexp mask. It works fine for the first time but another search value doesn't replace. But why?</p>
<pre><code>const reg = /(^\d{1,2})\s(may)\s(\d{4})/
var str = `22 may 2024 ac 22 may 2024`
for (i=0; i<2;i++){
var newStr = str.replace(reg, "");}
console.log(newStr);
</code></pre>
 
Top