/ Published in: Groovy

Example of working with regexp sub-matches via Groovy way
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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'" }
Comments
