Return to Snippet

Revision: 62499
at February 27, 2013 18:46 by alces


Initial Code
str = "<img width=20 height=20 src='./img/but-small.jpg'/>"
str2 = str.replaceAll(/width=(\d+) height=(\d+) src='(.+)-small\.jpg'/) {ma, wi, he, nm ->
 "width=${new Integer(wi) * 2} height=${he.toInteger() * 2} src='$nm-large.jpg'"
}
assert str2 == '<img width=40 height=40 src='./img/but-large.jpg'/>'

Initial URL
replace_all_groovy_way

Initial Description
Example of working with regexp sub-matches via Groovy way

Initial Title
Groovy way to replace regexp matches

Initial Tags
regexp

Initial Language
Groovy