regex: multiline with separation line pattern

eftshift0 :

I have this monster of a file. It can be split in blocks that look like this:

========
Title: title 1
optional subtitle
====
content 1
content 2

content 3

====
Title: title 2
========
content 4
content 5
content 6

So, we have two blocks there, right?

I'm trying to split with something like this:

(?:^=+\n)(^Title: .*\n)(^.*\n)?(?:^=+\n)((.*\n)(?!=+))+

Now, I can See that the groups get separated fine, I get the two groups (this is in Java, by the way, using Pattern.compile using Pattern.MULTILINE) but when I want to get the content, that part is empty. It is being included as part of the whole group (if I call match.group() with no index, but group(3) or group(4) fail to capture anything). What am I missing there?

allan gm2555 :

This works (?:^=+\n)(^Title: .*\n)(^.*\n)?(?:^=+\n)(((.*\n)(?!=+))+). You should group the last part.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=322182&siteId=1