mardi 20 décembre 2016

Java regex to extract text sequences across multiple lines

Given an excerpt of text like

Preface (optional, up to multiple lines)...
Main : sequence1
   sequence2
   sequence3
   sequence4
Epilogue (optional, up to multiple lines)

which Java regular expression could be used to extract all the sequences (i.e. sequence1, sequence2, sequence3, sequence4 above)? For example, a Matcher.find() loop?

Each "sequence" is preceded by and may also contain 0 or more white spaces (including tabs).

The following regex

(?m).*Main(?:[ |t]+:(?:[ |t]+(\S+)[\r\n])+

only yields the first sequence (sequence1).

Aucun commentaire:

Enregistrer un commentaire