JavaScript regex multiline flag doesn't work

前端 未结 5 1675
清酒与你
清酒与你 2020-11-22 09:41

I wrote a regex to fetch string from HTML, but it seems the multiline flag doesn\'t work.

This is my pattern and I want to get the text in h1 tag.

5条回答
  •  难免孤独
    2020-11-22 10:34

    The dotall modifier has actually made it into JavaScript in June 2018, that is ECMAScript 2018.
    https://github.com/tc39/proposal-regexp-dotall-flag

    const re = /foo.bar/s; // Or, `const re = new RegExp('foo.bar', 's');`.
    re.test('foo\nbar');
    // → true
    re.dotAll
    // → true
    re.flags
    // → 's'
    

提交回复
热议问题