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 7176907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:36:12+00:00 2026-05-28T16:36:12+00:00

Not a regex expert, but I know enough to be dangerous, need some help

  • 0

Not a regex expert, but I know enough to be dangerous, need some help with an expression I am working on. Long story short, a recent database upgrade has invalidated thousands of queries within string literals of a legacy application that I support. I am writing a few expressions to capture the majority of these and hopefully fix them programatically.

Consider the following:

Query query = session
                .createSQLQuery("SELECT distinct p.userid, p.name, f.hsid, "
                        + "p.vid, p.vname, p.paymentdate, p.amount "
                        + "FROM vk.payment p, (select * from vs.fuser) fu, (select * from vs.fac) f "
                        + "WHERE  p.description = 'Check' AND "
                        + "p.paymentdate >= :startDate and p.paymentdate <= :endDate AND "
                        + "fu.userid = p.userid AND fu.facid = f.facid "
                        + "ORDER BY p.userid");
        query.setParameter("startDate", startDate);
        query.setParameter("endDate", endDate);

I have the following DOTALL expression to attempt and capture simply the ugly contents of the method argument.

(?s)(?<=\.createSQLQuery\(")(.*)(?="\)\;)

I specify the DOTALL flag with (?s) a non-capturing look behind to get \.createSQLQuery\(", capture everything including line breaks with (.*), and finally a non capturing positive lookahead to stop the capture at "\)\;.

I am expecting to capture the following:

SELECT distinct p.userid, p.name, f.hsid, "
                            + "p.vid, p.vname, p.paymentdate, p.amount "
                            + "FROM vk.payment p, (select * from vs.fuser) fu, (select * from vs.fac) f "
                            + "WHERE  p.description = 'Check' AND "
                            + "p.paymentdate >= :startDate and p.paymentdate <= :endDate AND "
                            + "fu.userid = p.userid AND fu.facid = f.facid "
                            + "ORDER BY p.userid

Instead the expression is a lot greedier than I anticipated and is capturing this:

SELECT distinct p.userid, p.name, f.hsid, "
                            + "p.vid, p.vname, p.paymentdate, p.amount "
                            + "FROM vk.payment p, (select * from vs.fuser) fu, (select * from vs.fac) f "
                            + "WHERE  p.description = 'Check' AND "
                            + "p.paymentdate >= :startDate and p.paymentdate <= :endDate AND "
                            + "fu.userid = p.userid AND fu.facid = f.facid "
                            + "ORDER BY p.userid");
            query.setParameter("startDate", startDate);
            query.setParameter("endDate", endDate);
               ... to EOF

The thing is that without the DOTALL the expression works as expected on a single line:

Query query = session.createSQLQuery("SELECT .... ");

and captures without the remaining characters on the end…

SELECT .... 

Is there some aspect of DOTALL that every regex guru seems to know that does not seem to be documented anywhere? Does DOTALL not work with positive lookahead?

I appreciate any help!

  • 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-28T16:36:13+00:00Added an answer on May 28, 2026 at 4:36 pm

    Make the * quantifier non-greedy by adding a ? after it, like so: .*?

    Also why are you even using lookarounds? It can lead to undesired behavior in some cases to use them without thought like this. (And it always irritates me. (-; )

    You could just use:

    (?s)\.createSQLQuery\("(.*?)"\);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm no expert in regex but I need to parse some input I have
i'm not a regex expert but i know how to make simple regex. But
I don't really know what to entitle this, but I need some help with
I need help on regex or preg_match because I am not that experienced yet
I need a regex that will match blahfooblah but not blahfoobarblah I want it
I dont like others do my duties, but i'm not a RegEx expert and
I need some help with a regex conundrum pls. I'm still getting to grips
I'm not an expert with regex but tried my hand with validating a field
First, a disclaimer. I know a little about regex's but I'm no expert. They
Ok I know everyone is going to tell me not to use RegEx for

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.