Java regular expression to match _all_ whitespace characters

前端 未结 7 408
别那么骄傲
别那么骄傲 2020-12-08 02:36

I\'m looking for a regular expression in Java which matches all whitespace characters in a String. \"\\s\" matches only some, it does not match   and s

7条回答
  •  自闭症患者
    2020-12-08 02:58

    You clarified the question the way as I expected: you're actually not looking for the String literal   as many here seem to think and for which the solution is too obvious.

    Well, unfortunately, there's no way to match them using regex. Best is to include the particular codepoints in the pattern, for example: "[\\s\\xA0]".

    Edit as turned out in one of the comments, you could use the undocumented "\\p{Z}" for this. Alan, can you please leave comment how you found that out? This one is quite useful.

提交回复
热议问题