Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

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

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:

"hello|world".split("|"); --> {"hello", "world"}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

in Java 1.5+:

"hello|world".split(Pattern.quote("|"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...