<p>I wanted to grep for java process and then find the max heap memory used.
I tried this</p>

<pre><code>def ex =['sh','-c','ps -aef | grep Xmx']
String str =  ex.execute().text
</code></pre>

<p>while <code>str</code> has something like <em>java -Xmx1024M /kv/classes/bebo/ -Xms512M</em>
How do I extract the value <em>1024M</em>? I was planning to user java regex but thought someone might know a cool way in groovy.</p>

In Java:
```
```
String ResultString = null;
Pattern regex = Pattern.compile("-Xmx(\\d+M)");
Matcher regexMatcher = regex.matcher(str);
if (regexMatcher.find()) {
    ResultString = regexMatcher.group(1);
}
```
```