I met the following token in a regular expression: [\s\S]*?
If I understand this correctly, a character class means "match whitespace or no spaces." Therefore, it will not do the same as .*?
One possible difference is that usually . does not match newlines. However, this regular expression was written in Ruby and the m modifier was passed, which means that . really matches newlines.
Is there any other reason to use [\s\S]*? instead of .*?
In case this helps, the regular expression that I look up appears in the sprockets library in the constant HEADER_PATTERN on line 97. The full expression is:
/ \A \s* ( (\/\* ([\s\S]*?) \*\/) | (\#\#\# ([\s\S]*?) \#\#\#) | (\/\/ ([^\n]*) \n?)+ | (\# ([^\n]*) \n?)+ ) /mx
ruby regex
Rupert madden-abbott
source share