下面给出了样本内容,我需要得到" body {"和"}"。我试过模式匹配器,但没有找到。有人可以帮我这个。
body {
font-family: Arial, Helvetica, sans-serif;
font-style: normal;
font-size: 10pt
color: #000000;
}
以下是代码:
String patt1 = "body {";
String patt2 = "}";
Pattern p1 = Pattern.compile(Pattern.quote(patt1) + "(.*?)" + Pattern.quote(patt2));
Matcher m1 = p1.matcher(cssContent);
while (m1.find())
{
System.out.println("Mathced string : "+m1.group(1));
}
答案 0 :(得分:0)
为它创建Regex
模式:
String hello = "body {font-family: Arial, Helvetica, sans-serif; font-style: normal; font-size: 10pt color: #000000; }";
Pattern pattern = Pattern.compile("\\{(.+?)\\}", Pattern.DOTALL | Pattern.MULTILINE);
Matcher matcher = pattern.matcher(hello);
if (matcher.find()) {
System.out.println(matcher.group(1));
}