Reputation:
What is the purpose or the effect of |\s?
in ([\s\S]+|\s?)
? Wouldn't the expression be the same without it as ([\s\S]+)
?
Upvotes: 1
Views: 275
Reputation: 149020
It isn't exactly the same. ([\s\S]+|\s?)
would match an empty string, while ([\s\S]+)
would not.
However, ([\s\S]*)
would be equivalent.
Upvotes: 4
Reputation: 11116
that means either one or more of all characters
or only one or zero space
[\s\S]+
is equivalent to .+
and \s?
means an optional space
Upvotes: 0