java正则表达式,{"FCSTYear":{"varName":"FCSTYear","varSource":"Varchar","varValue":"FY22"}}匹配得到varName和varValue后的值
时间: 2023-10-05 15:14:38 浏览: 86
JAVA 正则表达式
要匹配varName和varValue后的值,你可以使用下面的正则表达式:
```
"varName":"([^"]*)".*?"varValue":"([^"]*)"
```
在Java中使用Pattern和Matcher类进行匹配,示例代码如下:
```java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
public static void main(String[] args) {
String input = "{\"FCSTYear\":{\"varName\":\"FCSTYear\",\"varSource\":\"Varchar\",\"varValue\":\"FY22\"}}";
String pattern = "\"varName\":\"([^\"]*)\".*?\"varValue\":\"([^\"]*)\"";
Pattern regex = Pattern.compile(pattern);
Matcher matcher = regex.matcher(input);
while (matcher.find()) {
String varName = matcher.group(1);
String varValue = matcher.group(2);
System.out.println("varName: " + varName);
System.out.println("varValue: " + varValue);
}
}
}
```
这样你就可以得到varName的值为"FCSTYear",varValue的值为"FY22"。
阅读全文