What does the regular expression /_/g mean?

后端 未结 3 570
再見小時候
再見小時候 2020-11-29 17:03

JavaScript:

.replace(/_/g,\" \");

I have it in my code but can\'t remember why or what it does! Can one of you regular expression gurus hel

3条回答
  •  囚心锁ツ
    2020-11-29 17:57

    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, ' ');
    

提交回复
热议问题