What does regex "\\p{Z}" mean?

BRabbit27 picture BRabbit27 · May 12, 2015 · Viewed 19.4k times · Source

I am working with some code in java that has an statement like

String tempAttribute = ((String) attributes.get(i)).replaceAll("\\p{Z}","")

I am not used to regex, so what is the meaning of it? (If you could provide a website to learn the basics of regex that would be wonderful) I've seen that for a string like

ept as y it gets transformed into eptasy, but this doesn't seem right. I believe the guy who wrote this wanted to trim leading and trailing spaces maybe.

Answer

Alex Shesterov picture Alex Shesterov · May 12, 2015

It removes all the whitespace (replaces all whitespace matches with empty strings).

A wonderful regex tutorial is available at regular-expressions.info. A citation from this site:

\p{Z} or \p{Separator}: any kind of whitespace or invisible separator.