简体   繁体   English

正则表达式:Java提取xml标记之间的内容

[英]Regex: Java extract content between xml tags

I have an xml string 我有一个xml字符串

<client>12345abcde</client>

and I want to use regex to extract the contents between client tag and store in a variable. 我想使用正则表达式提取客户端标签之间的内容并存储在变量中。 Currently I have 目前我有

Matcher m = Pattern.compile("(.*)<client>(.*)</client>(.*)").matcher("<client>12345abcde</client>"); 
    m.matches(); 

String value = m.group(2);

but that doesn't seem to work. 但这似乎不起作用。

Matcher m =   Pattern.compile(".*<client>(.*)<\\/client>.*").matcher("<client>12345abcde</client>"); 
m.matches(); 

String value = m.group(2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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