Java: split() method with pipe special character

前端 未结 7 1372
悲&欢浪女
悲&欢浪女 2021-01-24 16:14

I have a String = \"Hello-new-World\". And when i use the split() method with different regex values, it acts differently.

String str = \"Hello-new-world\"
Strin         


        
相关标签:
7条回答
  • 2021-01-24 16:58

    An unescaped | is parsed as a regex meaning "empty string or empty string," so use

    str.split("\\|");
    

    | having special meaning OR in regex

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