Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在两个字符串之间查找字符串_Java - Fatal编程技术网

Java 在两个字符串之间查找字符串

Java 在两个字符串之间查找字符串,java,Java,下面给出了示例内容,我需要获得“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.quo

下面给出了示例内容,我需要获得“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));
 }

为它创建一个
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));
    }

我尝试了pattern matcher,但没有找到-请显示您尝试的代码,人们会帮助您修复;)向我们显示您尝试使用的代码。添加您尝试使用的代码。我们可以试着改正错误。是文本文件吗?html?你只使用过一次吗?提供更多信息和我将使用的字符串代码