What does regular expression \\s*,\\s* do?

后端 未结 2 728
栀梦
栀梦 2021-02-07 00:57

I am wondering what this line of code does to a url that is contained in a String called surl?

String[] stokens = surl.split(\"\\\\s*,\\\\s*\");
<
相关标签:
2条回答
  • 2021-02-07 01:25

    That regex "\\s*,\\s*" means:

    • \s* any number of whitespace characters
    • a comma
    • \s* any number of whitespace characters

    which will split on commas and consume any spaces either side

    0 讨论(0)
  • 2021-02-07 01:26
    • \s stands for "whitespace character".
    • It includes [ \t\n\x0B\f\r]. That is: \s matches a space( ) or a tab(\t) or a line(\n) break or a vertical tab(\x0B sometimes referred as \v) or a form feed(\f) or a carriage return(\r) .

    \\s*,\\s*
    

    It says zero or more occurrence of whitespace characters, followed by a comma and then followed by zero or more occurrence of whitespace characters.

    These are called short hand expressions.

    You can find similar regex in this site: http://www.regular-expressions.info/shorthand.html

    0 讨论(0)
提交回复
热议问题