Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:37+00:00 2026-05-31T13:29:37+00:00

I’m having troubles getting a regex to work. I’m trying to parse a large,

  • 0

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:

  1. 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 ordered Invoice, Package, Mapping, Post in the text file, with Post being optional so it may not even be there) and mapping is toward the end.

  2. The <(ESQL|ProcessInvoice)> section actually takes ProcessInvoice 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, just Invoice) with no alternation anywhere. It will skip past the first section and take the second one.

I admit I’m no regex guru, but this seems like rather odd behaviour. Calling .reset() on the Matcher doesn’t make it recognize an earlier block either, and .find() only locates one match instead of iterating through all the possible matches.

—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):

  1. Invoice
  2. Package
  3. Mapping

And data:

  1. ESQL Block 1
    ESQL Block 2
  2. ESQL Block 3
  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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:29:38+00:00Added an answer on May 31, 2026 at 1:29 pm

    I’d change .* to .*? to make it non-greedy. That will probably help you.

    But really you’d be better using an XML parser. You say you can’t use an XML parser because the XML is embedded inside other text. Then I’d suggest you extract the entire block of XML (using a regex or another appropriate method) and put it into an XML parser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.