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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:02:14+00:00 2026-05-19T05:02:14+00:00

First, I confess I’m not realy experimented with regular expressions. I know how use

  • 0

First, I confess I’m not realy experimented with regular expressions. I know how use it but when I want to build one, it’s something else… I’m going to document me.

I want to extract the WHERE clause in a SQL query. My goal is to be able to add an condition, like this:

SELECT * FROM myTbl WHERE columnA = 'B' AND columnB = 'C' ORDER BY columnX GROUP BY columnZ LIMIT 5

TO :

SELECT * FROM myTbl WHERE columnC = 'D' AND (columnA = 'B' AND columnB = 'C') ORDER BY columnX GROUP BY columnZ LIMIT 5

I tried some expression but I’m so void…

(where (.*)(?<=order by))

I wanted to get all between ‘where’ and (‘order by’ or ‘limit’ or ‘group by’)…

Anyone have an advice for me ? I have done some search and I don’t find anything like this. I found SQL Parser but these engines are too big compared to the task I want to complete.

Thank you.

  • 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-19T05:02:15+00:00Added an answer on May 19, 2026 at 5:02 am

    Since the WHERE clause can be quite complex (including subqueries which may include an ORDER BY in some cases, for instance when used with FOR XML), so you will not be able to really find an always reliably working solution with a regex.

    A better solution would be to use a proper SQL parser which generates an AST, and then you can just extract the WHERE clause from that. For T-SQL, you could use the parser from the bsn ModuleStore project (LGPL license). Modifying the AST is easy and you can re-script the statement afterwards.

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

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
First of all, I know I asked a similar question before but this one
First off I confess my ignorance, I've learned everything I know about Objective-C in
first I used onDestroy() method as below to make something when my app is
First I want to thank you guys here, because your posts have gotten me
First I will ask users How many names you want to enter?. Once they
First of all i have to those categoryIDs 1-whos parentcategoryID only appears one 2-ParentCategoryID
I must confess that today is my first day using either Sweave or LaTeX.
I will confess I'm very new to Python and I don't really know what
First, I have a list of QWidget s that I won't know the length

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.