Java: split() method with pipe special character

前端 未结 7 1451
悲&欢浪女
悲&欢浪女 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:55

    The pipe has different meaning in regular expression, so if you want to use it you need to escape the special character.

    str.split("\\|");
    

提交回复
热议问题