javascript - The regular expression w only matches one letter. If you want to match a word, how do you write it?
習慣沉默
習慣沉默 2017-06-30 09:57:25
0
4
741
var reg = new RegExp('\w'); var match = reg.exec('/hello/world/1'); console.log(match[0]);

The above log prints h. If you want to print hello, how do you do it?

習慣沉默
習慣沉默

reply all (4)
过去多啦不再A梦
var reg = new RegExp('\b\w+\b'); var match = reg.exec('/hello/world/1'); console.log(match[0]);

bMatch the beginning or end of a word.

    黄舟

    var pattern = /hello/;

    var str = "helloword"; console.log(pattern.exec(str)[0]);

    Recommend you this website http://www.runoob.com/regexp/...

      Peter_Zhu

      First w matches the literal value w
      wmatches the characters appearing in the word, such as a to z and_
      If you need to match multiple

      • You can add*at the end to indicate 0 or more

      • You can add+at the end to indicate one or more

        漂亮男人
        /[a-zA-Z]*/
          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!