Closed KennethKinLum closed 4 years ago
Given that /[.\n]/.test("x")
returns false, I suspect this doesn't do what you think it does. /(.|\n)/
would work. But I don't think it's worthwhile to add noise to the text with different suggestions when [^]
does its job just fine.
ah... i forgot the .
in the []
has special meaning... oops... is there a way to make .
mean the same thing even inside the []
?
I don't think there is
ok, then it can be
(.|\n)
but I guess it maybe a bit more verbose than [^]
or [\s\S]
but it is more clear than [^]
or [\s\S]
but then...
.
Matches any single character except line terminators: \n, \r, \u2028 or \u2029. For example, /.y/ matches "my" and "ay", but not "yes", in "yes make my day".
that's why "a\r\nb".match(/a(.|\n)*b/)
won't match.
(in p.155 of your book, on the topic Greed, of RegExp)
I think the dotall problem is related to the missing
s
flag such as in Firefox.Now we can use
[^]
and that's nice way. I also read that[\s\S]
(or any pair such as[\w\W]
) can also work.Now I think
[.\n]
is also good and worth a mentioning because it gives a clear indication of what wants to be matched, than any other forms out there.