-2

I have a string, like this:

let str = `... <!-- My -- comment
 test --> ..  <!----> ..
`;

And I want to get the comment part of the HTML string.

I try to use the Regular Express do this.

let reg = /<!(.|\s)*?>/g

str.match(reg) // ["<!-- My -- comment↵ test -->", "<!---->"]

This is ok. But When I try to another Regular Express.

let reg = /<![.|\s]*>/g;
str.match(reg) // null

So what's different in two Regular Express. Why the second is fail?

Olian04
  • 6,480
  • 2
  • 27
  • 54
user8930932
  • 125
  • 1
  • 9

1 Answers1

1
  • [.|\s] will match the literal characters ., |, or any space character.
  • When you use (.|\s) then . will match any character but spaces, and | is the logical or operation.

https://regex101.com/r/xsnTbk/1

Olian04
  • 6,480
  • 2
  • 27
  • 54