在TEST之间以粗体显示字符串: [" 1"," 2"] 。我想从[到]得到一个字符串的一部分。问题是我有多个打开和关闭括号,如: 州:[" VA"," PA"],TEST: [" 1"," 2"] ,城市:[" NYC"]
但我只对在TEST之后得到字符串感兴趣:。任何人都可以建议我如何提取它。
提前致谢。
例如:
__init__.py
从上面我只想得到[" 1"," 2"]
State:["VA","PA"],TEST: ["1","2"],City:["NYC"]
同样地,我只想得到[" 1"," 2"],这是在TEST之后:从开括号到闭括号。
答案 0 :(得分:2)
你可以用正则表达式来做,例如:
String src = "State:[\"VA\",\"PA\"],TEST: [\"1\",\"2\"],City:[\"NYC\"]";
Pattern pattern = Pattern.compile("TEST: \\[(.*?)\\]");
Matcher matcher = pattern.matcher(src);
if (matcher.find()) {
System.out.println(matcher.group(1));
}