I'm having troubles getting a regex to work. I'm trying to parse a large, multiline block of text for certain XML tags. The reason I'm not parsing this with an XML library however is it's actually part of a block of ESQL as well. The line I'm using is as follows:
Pattern.compile(".*'(Invoice|Package|Mapping|Post)' AS STAGE.*(<(ESQL|ProcessInvoice)>.+)</(ESQL|ProcessInvoice)>).*", Pattern.DOTALL);
My problem is actually two fold:
The
(Invoice|Package|Mapping|Post)
section only matches to Invoice, unless I remove Invoice from the list. Then it matches to only Mapping. What sticks me as odd is that Package is in the middle of the text block (the blocks are orderedInvoice, Package, Mapping, Post
in the text file, with Post being optional so it may not even be there) and mapping is toward the end.The
<(ESQL|ProcessInvoice)>
section actually takesProcessInvoice
block (the very last block, past three<ESQL>
blocks at the end). If I remove the(ESQL|ProcessInvoice)
part and just make it<ESQL>
it will, oddly, take the Package block, again, rather than the first block for the Invoice. This continues to be a problem even if I pare this down to only be one of the four sections from before (so, justInvoice
) with no alternation anywhere. It will skip past the first section and take the second one.
---Addendum--- Example input as follows (edited for content):
CREATE COMPUTE MODULE Module_Name
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
Header stuff,
'Invoice' AS STAGE,
Gibberish here
'<Rule>
<ESQL>
ESQL Block 1
</ESQL>
<ESQL>
ESQL Block 2
</ESQL>
</Rule>' AS CONTENT);
Header stuff,
'Package' AS STAGE,
Gibberish here
'<Rule>
<ESQL>
ESQL Block 3
</ESQL>
</Rule>' AS CONTENT);
Header stuff as well,
'Mapping' AS STAGE,
Gibberish here too
'<ProcessInvoice>
Another ESQL Block
</ProcessInvoice>' AS CONTENT);
END;
END MODULE;
The intended groupings should be (respectively):
- Invoice
- Package
- Mapping
And data:
- ESQL Block 1 ESQL Block 2
- ESQL Block 3
- Another ESQL Block
I should mention I altered my regex slightly now to account for , and it is now as follows:
.*?'(Package|Invoice|Post)' AS STAGE.*?<Rule>(.+?)</Rule>.*?
This alternation seems to work now for three of the four possible sections, but I believe part of my earlier trouble was trying to use <(ESQL|ProcessInvoice)>
inside of another group. Trying to do without <Rule>(.+?)</Rule>.*?
and instead do even just (<ESQL>.+?</ESQL>)
doesn't want to work now.