What does the regular expression /_/g mean?

we can use the expression / /g to search or extract a pattern more than once, you can use the g flag.


Returns a new string with all the underscores in the source string replaced with spaces.


The regex matches the _ character.

The g means Global, and causes the replace call to replace all matches, not just the first one.


Like everyone else has said, it replaces all underscores with spaces. So "Hello_there." would become "Hello there."

But along with the answer, I want to suggest something to you. Use comments.

In your code say something like:

// Replaces all underscores so that blah blah blah blah blah..
var hello = "Hello_there."
    .replace(/_/g, ' ');