Skip to content
Advertisement

How to replace string using regex in javascript?

How to check a string and replace the space into “_” ?

JavaScript

Please help me out 🙂

Advertisement

Answer

Check this out. I think it’s gonna help
Hints:

  1. /:(w+s*)+/g Separates the :nokibul amin mezba jomadder as a group.
  2. Replace the group with index-wise templating {0}, {1}{n}.
  3. Mapping the groups. Ex: :nokibul amin mezba jomadder to :nokibul_amin_mezba_jomadder.
  4. Finally, replacing the templates {index} with groups.

JavaScript
Advertisement