如何在java中的引号之间获取数据? [英] how to get data between quotes in java?
本文介绍了如何在java中的引号之间获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这行文字的引号数可能会改变如下:
I have this lines of text the number of quotes could change like:
Here just one "comillas"
But I also could have more "mas" values in "comillas" and that "is" the "trick"
I was thinking in a method that return "a" list of "words" that "are" between "comillas"
我如何获得结果应该在引号之间的数据?:
how I obtain the data between the quotes the result should be?:
comillas
mas,comillas,trick
a,words,are,comillas
comillas
mas, comillas, trick
a, words, are, comillas
推荐答案
您可以使用正则表达式来获取此类信息。
You can use a regular expression to fish out this sort of information.
Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(line);
while (m.find()) {
System.out.println(m.group(1));
}
此示例假定要解析的行的语言不支持双引号的转义序列在字符串文字中,包含跨越多个行的字符串,或支持其他字符串的分隔符,如单引号。
This example assumes that the language of the line being parsed doesn't support escape sequences for double-quotes within string literals, contain strings that span multiple "lines", or support other delimiters for strings like a single-quote.
这篇关于如何在java中的引号之间获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文