简体   繁体   中英

Java regex pattern to split String based on delimiter string “|-|”

I have a java string delimited by |-| like below.

Can't find |-| deliter based split any where else this is unique.

String agent = "iOS|-|iPhone|-|18.2.3|-|kuoipo-kjpopoo-kijhloii-kllkijii";

What is the correct regex to split the contents in string Array like below.

String[] dataarray;
dataarray[0]="iOS";
dataarray[1]="iPhone";
dataarray[2]="18.2.3";
dataarray[3]="kuoipo-kjpopoo-kijhloii-kllkijii";

Already tried:

agent.split("\\|-\\|");

Thanks in Advance.

Won't work

agent.split("|-|")

Do

agent.split("\\|-\\|")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM