user3111525 user3111525 - 5 months ago 48
Groovy Question

Groovy: splitting multi-line string

I have got a file that looks like this:

Bar foo Bar / asda
Lorem ipsum
ipsum lorem;

I want to split the text by a regex
, meaning line beginning and ending with delimeter
. I have tried various variants including
but it does not work. What am I missing?

Answer Source

In Groovy regex (that actually uses Java regex library), you may use a Pattern.MULTILINE inline embedded flag (?m) that will make ^ match a start of the line and $ the end of the line (rather than a whole string):

Multiline mode can also be enabled via the embedded flag expression (?m).


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download