[英]java split regex: split string using any text between curly brackets and keep the delimiter
尝试以这种方式拆分
yourString.split("\\s(?=\\{)|(?<=\\})\\s")
它将在每个后面有{
或之前}
空间上分割。
演示版
for (String s : "hello {world} this is {stack overflow} and this is my string"
.split("\\s(?=\\{)|(?<=\\})\\s"))
System.out.println(s);
输出
hello
{world}
this is
{stack overflow}
and this is my string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.