gpt4 book ai didi

Java - 由定界符分割

转载 作者:行者123 更新时间:2023-11-30 07:26:52 27 4
gpt4 key购买 nike

给定_<A_>_<B_>_<Z_> , 我想提取 A, B, C在数组中。

基本上_<是起始分隔符,_>是结束分隔符。

最佳答案

您可以使用 lookaround assertions仅匹配标签的内容。

String text = "_<A_>_<B_>_<Z_>";

List<String> Result = new ArrayList<String>();

Pattern p = Pattern
.compile("(?<=_<)" + // Lookbehind assertion to ensure the opening tag before
".*?" + // Match a less as possible till the lookahead is true
"(?=_>)" // Lookahead assertion to ensure the closing tag ahead
);
Matcher m = p.matcher(text);
while(m.find()){
Result.add(m.group(0));
}

关于Java - 由定界符分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136267/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com