Java regular expression to match _all_ whitespace characters

前端 未结 7 426
别那么骄傲
别那么骄傲 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条回答
  •  猫巷女王i
    2020-12-08 02:57

      is not a whitespace character, as far as regexpes are concerned. You need to either modify the regexp to include those strings in addition to \s, like /(\s| |%20)/, or previously parse the string contents to get the ASCII or Unicode representation of the data.

    You are mixing abstraction levels here.

    If, what after a careful reread of the question seems to be the case, you are after a way to match all whitespace characters referring to standard ASCII plus the whitespace codepoints, \p{Z} or \p{Zs} will do the work.

    You should really clarify your question because it has misled a lot of people (even making the correct answer to have some downvotes).

提交回复
热议问题