Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the regex [\s\S-[<>]]*

Tags:

regex

I have this regex: [\s\S-[<>]]*

Could you please help me understand what does this expression stand for? From what I see it means a character class formed of spaces and a range from non-space characters to < or >?

It doesn't make much sense..

Thanks!

like image 614
Dan L. Avatar asked May 24 '12 13:05

Dan L.


People also ask

What does [\ s mean in regex?

Definition and Usage The \s metacharacter matches whitespace character. Whitespace characters can be: A space character.

What does \\ s+ S+ mean?

The Difference Between \s and \s+The plus sign + is a greedy quantifier, which means one or more times. For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.

What does \\ s+ in Java mean?

\\s - matches single whitespace character. \\s+ - matches sequence of one or more whitespace characters.

What is the difference between * and * in regex?

represents a single character (like the regex's . ) while * represents a sequence of zero or more characters (equivalent to regex . * ).


1 Answers

This is a variant only supported by a few regex engines (.NET, JGSoft, XML Schema and XPath but not for example native Java regex), and it's called character class substraction.

For example,

[A-Z-[EFG]]

matches any letter from A to Z except E, F or G.

But in your case, it really doesn't make much sense because [\s\S] matches any character - the same result (in any regex flavor) can be achieved by

[^<>]*
like image 188
Tim Pietzcker Avatar answered Oct 14 '22 09:10

Tim Pietzcker