gpt4 book ai didi

java - 如何在 xml 标记之间提取多语言字符串

转载 作者:行者123 更新时间:2023-11-29 08:44:10 25 4
gpt4 key购买 nike

我正在尝试提取 xml 标记之间的文本。标签之间的文本是多语言的。例如:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
तुम्हारा नाम क्या है
</string>

我试着用谷歌搜索它并得到了一些正则表达式,但那没有用这是我试过的:

String str = "<string xmlns="+
"http://schemas.microsoft.com/2003/10/Serialization/"+">"+
"तुम्हारा नाम क्या है"+"</string>";

final Pattern pattern = Pattern.compile("<String xmlns="+
"http://schemas.microsoft.com/2003/10/Serialization/"+">(.+?)</string>");

final Matcher matcher = pattern.matcher(str);
matcher.find();
System.out.println(matcher.group(1));

给定的String格式是

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
तुम्हारा नाम क्या है
</string>

预期的输出是:

तुम्हारा नाम क्या है

它给我一个错误

最佳答案

此模式匹配预期部分和 $1给你预期的结果:

/<string .*?>(.*?)<\\/string>/

Online Demo

但是强烈建议停止使用正则表达式这样做......!你得找个JAVA的HTML解析器,简单抓取<string>的内容标签。

关于java - 如何在 xml 标记之间提取多语言字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680363/

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