I'm using a JavaScript regular expression /(<mos>[\s\S]*?<\/mos>)/g
to find XML blocks in a log file that looks roughly like this:
Entry 1: <mos>...</mos>
Entry 2: <mos>...</mos>
However, sometimes the logging process encounters an error and doesn't finish writing an entry to the file, in which case it looks like this:
Entry 1: <mos>Error!
Entry 2: <mos>...</mos>
When this happens the regular expression matches everything from the opening <mos>
tag in entry 1 to the closing </mos>
tag in entry 2 which causes problems when processing the XML later.
It seems that somehow matching the closing tags first and then looking back for their corresponding opening tags would avoid this, but I don't know how to do this or if it is possible with regular expressions.
Clarification: The ...
in the blocks delimited by the start and end tags can include newlines.