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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:29:45+00:00 2026-06-05T18:29:45+00:00

Given: ABC content 1 123 content 2 ABC content 3 XYZ Is it possible

  • 0

Given:

ABC
content 1
123
content 2
ABC
content 3
XYZ

Is it possible to create a regex that matches the shortest version of “ABC[\W\w]+?XYZ”

Essentially, I’m looking for “ABC followed by any characters terminating with XYZ, but don’t match if I encounter ABC in between” (but think of ABC as a potential regex itself, as it would not always be a set length…so ABC or ABcC could also match)

So, more generally: REGEX1 followed by any character and terminated by REGEX2, not matching if REGEX1 occurs in between.

In this example, I would not want the first 4 lines.

(I’m sure this explanation could potentially need…further explanation haha)

EDIT:

Alright, I see the need for further explanation now! Thanks for the suggestions thus far. I’ll at least give you all more to think about while I start looking into how each of your proposed solutions can be applied to my problem.

Proposal 1: Reverse the string contents and the regex.

This is certainly a very fun hack that solves the problem based on what I explained. In simplifying the issue, I failed to also mention that the same thing could happen in reverse because the ending signature could exist later on also (and has proven to be in my specific situation). That introduces the problem illustrated below:

ABC
content 1
123
content 2
ABC
content 3
XYZ
content 4
MNO
content 5
XYZ

In this instance, I would check for something like “ABC through XYZ” meaning to catch [ABC, content 1, XYZ]…but accidentally catching [ABC, content 1, 123, content 2, ABC, content 3, XYZ]. Reversing that would catch [ABC, content 3, XYZ, content 4, MNO, content 5, XYZ] instead of the [ABC, content 2, XYZ] that we want again. The point is to try to make it as generalized as possible because I will also be searching for things that could potentially have the same starting signature (regex “ABC” in this case), and different ending signatures.

If there is a way to build the regexes so that they encapsulate this sort of limitation, it could prove much easier to just reference that any time I build a regex to search for in this type of string, rather than creating a custom search algorithm that deals with it.

Proposal 2: A+B+C+[^A]+[^B]+[^C]+XYZ with IGNORECASE flag

This seems nice in the case that ABC is finite. Think of it as a regex in itself though. For example:

Hello!GoodBye!Hello.Later.

VERY simplified version of what I’m trying to do. I would want “Hello.Later.” given the start regex Hello[!.] and the end Later[!.]. Running something simply like Hello[!.]Later[!.] would grab the entire string, but I’m looking to say that if the start regex Hello[!.] exists between the first starting regex instance found and the first ending regex instance found, ignore it.

The convo below this proposal indicates that I might be limited by regular language limitations similar to the parentheses matching problem (Google it, it’s fun to think about). The purpose of this post is to see if I do in fact have to resort to creating an underlying algorithm that handles the issue I’m encountering. I would very much like to avoid it if possible (in the simple example that I gave you above, it’s pretty easy to design a finite state machine for…I hope that holds as it grows slightly more complex).

Proposal 3: ABC(?:(?!ABC).)*?XYZ with DOTALL flag

I like the idea of this if it actually allows ABC to be a regex. I’ll have to explore this when I get in to the office tomorrow. Nothing looks too out of the ordinary at first glance, but I’m entirely new to python regex (and new to actually applying regexes in code instead of just in theory homework)

  • 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-05T18:29:46+00:00Added an answer on June 5, 2026 at 6:29 pm

    A regex solution would be ABC(?:(?!ABC).)*?XYZ with the DOTALL flag.

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

Sidebar

Related Questions

Given a table ABC with columns Col1, Col2 and Col3 it is possible to
I have below string in javascript var output = '<?xml version=1.0 encoding=UTF-8 standalone=yes?><abc><xyz><xyzResponse><URL>http%3A%2F%2Flocalhost%3A8080%2Fnet%2Fxyz.do%3Fpartner%3Ddummy%26id%3Dba0e245f-ae67-40b6-986d-3242acea4c04</URL><StatusMsg>SUCCESS</StatusMsg><ID>hello.com</ID><AID>test</AID></xyzResponse></xyz></abc>'; I
Given strings like these: string s1 = Abc; string s2 = ABC; What is
given i have the following block of code (function(){ var mb = { abc:function(){
Scenario: Change a member to ABC 60 days before anniversary date Given Repeat When+Then
Given two lists: chars = ['ab', 'bc', 'ca'] words = ['abc', 'bca', 'dac', 'dbc',
Given the above dynamically generated text (meaning that I can't just use an image),
How can I parse a String str = abc, \def,ghi\ ; such that I
How is it possible to give a jquery-plugin individual local variables, that are accessable
Given a string such as abc-def-ghi-jkl . Can the sed command extract the substring

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.