Reflection
Reflection

Reputation: 2106

Non-numeric characters inside regular expression's curly braces

Curly braces are useful to specify a specific amount of repetition in regular expressions.

However, I've just see the following regular expression: [\t\p{Zs}].

Is it correct to put non-numeric characters between curly braces? If so, what operation is it?

What is the significance of the fact that the curly braces appear in the square brackets?

Upvotes: 0

Views: 72

Answers (2)

anubhava
anubhava

Reputation: 785376

This regex:

[\t\p{Zs}]

Matches any one of the following:

  • \t - tab character
  • \p{Zs} a whitespace character that is invisible

Upvotes: 0

Jerry
Jerry

Reputation: 71568

\p{Zs} is a POSIX bracket expression and is equivalent to a character class, much like \s is a character class for [\v\r\n\t\f ]

\p{Zs} now refers to a space character, as you can see in the link I referred to above.

Upvotes: 1

Related Questions