user457586
user457586

Reputation:

What is the purpose/effect of |\s? in ([\s\S]+|\s?)

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

Answers (2)

p.s.w.g
p.s.w.g

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

aelor
aelor

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

Related Questions