Java String parsing including line break and regular expression
<p>I am parsing file having values</p>

<pre><code>kv {
  key "val1" 
  data "10"
}
kv {
  key "val2"
  data "20"
}
kv {
  key "val3"
}


Pattern p = Pattern.compile("\\s+key.+");

    Scanner sc = new Scanner(new File("kv.txt"));
    while (sc.hasNextLine()) {
        sc.nextLine();
        String line = sc.findInLine(p);

        if (line != null) {
            System.out.println(line);
        }
    }
</code></pre>

<p>Above code is picking fine all of the lines having value "key" but in some cases i am getting data which also have "data" elements as shown above in first two records. Wondering what regular expression i should be passing to Pattern.compile method that picks data till end braces - "}" of kv element.</p>

<p>Out put i am expecting is -> key "val1" data "10" AND key "val2" data "20" for first two kv records (string containing 4 substrings) and for the last one -> key "val3" only.</p>