1

I need to extract text from XML as follows:
...some xml code...
<!-- start -->
text to
be extracted
<!-- end -->
...some xml code...
I need a regular expression to output: text to be extracted

I tried something like:

(?<=\<!--\s*start\s*-->)(.*)(?=\<!--\s*end\s*-->)

any ides?

rperez
  • 8,430
  • 11
  • 36
  • 44
  • 4
    Why don't you use an XML-parser instead? (http://stackoverflow.com/questions/335250/parsing-xml-with-regex-in-java) – Hauns TM Jul 29 '12 at 20:21
  • or, if you want, you need a key `s`, that allows to `.` eat `\n`. So, you have multi-line, that separated by `\n`. `.`-symbol doesn't match `\n` general, but also need a key – gaussblurinc Jul 29 '12 at 20:39
  • Your regular expression should work if you enable single line mode. – rrrr-o Jul 30 '12 at 10:40

1 Answers1

0

this one did the trick:

(?<=\<!--\s*start\s*-->)((?s).*)(?=\<!--\s*end\s*-->)

thanks rrrr

rperez
  • 8,430
  • 11
  • 36
  • 44