I have file with content:
~LayerData
type="waypointlist"
type="waypointlistend"
type="track" name="Track1" color=#695cbb
type="trackpoint" latitude="43.5032064" longitude="16.4266248"
type="trackpoint" latitude="43.5071074767561" longitude="16.48329290000057"
type="trackend"
~EndLayerData
~LayerData
type="waypointlist"
type="waypointlistend"
type="track" name="Track2" color=#000000
type="trackpoint" latitude="43.51037193515589" longitude="16.491883500895977"
type="trackpoint" latitude="43.521582832754135" longitude="16.473187288140295"
type="trackend"
~EndLayerData
I'm extracing LayerData -> EndLayerData matches using:
Pattern p = Pattern.compile("(~LayerData(.|\n)*~EndLayerData)");
Matcher m = p.matcher(s);
As a result I get m.group() with three items: first two are identical and contain the complete file. Last one is "\n". I expected to receive Track1 and Track2 separated.
` in a string becomes\`.\nis a line break, if you want to match it you need to use\\n.