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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:58:22+00:00 2026-06-04T04:58:22+00:00

I need help creating the best possible regular expression for this problem. I have

  • 0

I need help creating the best possible regular expression for this problem.

I have combinations / sets of Starting and End Delimeters and I need to get ALL the substring / any words between the starting delimeter upto the end delimeter.

Assume this table of Delimeters:

START | END

CAT | DOG

APPLE | ORANGE

LION | ZEBRA

PANDA | CAT

sample Input:

substring1 CAT substring2 substring3 DOG substring4 substring5 CAT substring6
APPLE substring7 substring 8 ORANGE ORANGE substring9 DOG substring10 PANDA
substring11 CAT substring12 DOG substring13 LION substring10 substring11 ZEBRA substring12
CAT substring13 substring14 APPLE substring15 substring 16 ORANGE

The output must be:

  1. CAT substring2 substring3 DOG
  2. APPLE substrin7 substring8 ORANGE
  3. PANDA substring 11 CAT
  4. LION substring10 substring 11 ZEBRA
  5. APPLE substring15 substring16 ORANGE

My regular expression:

 CAT (.)*? DOG | APPLE (.)*? ORANGE | LION (.)*? ZEBRE |  PANDA (.)*? CAT 

I have problem dealing with string that has multiple occurence of other starting delimeter.

take for example:

CAT word1 word2 word3 word4 APPLE word5 word6 word7 DOG 

I know that it will match with this CAT (.)*? DOG but this is wrong since the substring contains one of the starting delimeters.

I just need a regex that that will get all the words between a starting delimeter upto its matching end delimeter if ever the substring does not contain any occurence of other starting delimeters.

any suggestion? Thanks

  • 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-06-04T04:58:23+00:00Added an answer on June 4, 2026 at 4:58 am

    The technique that helps us here is called “lookaround”.

    I Updated my answer after clarification of nfinium and feedback from jsobo

    CAT ((?!(APPLE|LION|PANA)).)*? DOG|APPLE ((?!(CAT|LION|PANDA)).)*? ORANGE|LION ((?!(CAT|APPLE|PANDA)).)*? ZEBRA|PANDA ((?!(APPLE|LION)).)*? CAT
    

    Given the input:

    substring1 CAT substring2 substring3 DOG substring4 substring5 CAT substring6 APPLE substring7 substring 8 ORANGE ORANGE substring9 DOG substring10 PANDA substring11 CAT substring12 DOG substring13 LION substring10 substring11 ZEBRA substring12 CAT substring13 substring14 APPLE substring15 substring 16 ORANGE  string CAT dkdkdkdkdk CAT dkdkdk dkdkdk ORANGE dkdkdkdk DOG etc. CAT word1 word2 word3 word4 APPLE word5 word6 word7 DOG wordx
    

    It matches

    CAT substring2 substring3 DOG
    APPLE substring7 substring 8 ORANGE
    PANDA substring11 CAT
    LION substring10 substring11 ZEBRA
    APPLE substring15 substring 16 ORANGE
    CAT dkdkdkdkdk CAT dkdkdk dkdkdk ORANGE dkdkdkdk DOG
    

    Specificaly, it will not match the following as indicated by nfinium

    CAT word1 word2 word3 word4 APPLE word5 word6 word7 DOG 
    

    And also matches as you pointed out

    CAT dkdkdkdkdk CAT dkdkdk dkdkdk ORANGE dkdkdkdk DOG 
    

    You say that it should match the following

    CAT substring12 DOG
    

    but I dont think it should not since the CAT from above is the end delimiter of

    PANDA substring11 CAT
    

    This regex produces the expected result of nfinium

    Note that as per the requirments of nfinium CAT can be a starting and an ending delimiter

    CAT | DOG
    PANDA | CAT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help creating a regular expression for redirecting my old URL's to new
I need some help in creating the best possible table schema for the following
I need help solving the problem below. I am creating a Windows Forms Application
I need some help figuring out the best way to proceed with creating a
This is probably a newbie question, but i really need help. I am creating
I need help creating the regex for a password. The password can contain letters,
I need help with creating a C# method that returns the index of the
I need your help in creating dynamic URL for SEO gains.. I tried to
I need a little help creating a catch-all error handling page in my ICEfaces
i need some help with creating file Im trying in the last hours to

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.