您可以使用环绕声断言来仅匹配标记的内容.
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));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
255 次 |
| 最近记录: |