how to use dotall flag for regex.exec()

后端 未结 4 869
我寻月下人不归
我寻月下人不归 2020-11-30 11:34

i want get to string in a multiline string that content any specific character and i want get to between two specific staring.

i used this regex and this work but if

4条回答
  •  半阙折子戏
    2020-11-30 11:48

    javascript doesn't support s (dotall) modifier. The only workaround is to use a "catch all" class, like [\s\S] instead of a dot:

    regex = new RegExp("\-{2}Head([\\s\\S]*)-{2}\/\Head")
    

    Also note that your expression can be written more concisely using a literal:

    regex = /--Head([\s\S]*)--\/Head/
    

提交回复
热议问题