Groovy grep a word

grepgroovy

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

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

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

Best Solution

Here's a groovy version that doesn't need the grep (or the sed :) :

("ps -aef".execute().text =~ /.*-Xmx([0-9]+M).*/).each { full, match -> println match }