What is the proper way of inserting a pipe into a Java Pattern expression?

后端 未结 4 947
情话喂你
情话喂你 2020-12-29 03:32

What is the proper way of inserting a pipe into a Java Pattern expression?

I actually want to use a pipe as a delimiter and not the or operator.

I.E:

4条回答
  •  抹茶落季
    2020-12-29 03:52

    "hello|world".split("\\\\|"); --> {"hello", "world"}
    

    First set of "\\" only yields the \ as the delimiter. Therefore 2 sets are needed to escape the pipe.

提交回复
热议问题