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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:59:45+00:00 2026-05-17T15:59:45+00:00

For regex what is the syntax for search until but not including? Kinda like:

  • 0

For regex what is the syntax for search until but not including? Kinda like:

Haystack:
The quick red fox jumped over the lazy brown dog

Expression:
.*?quick -> and then everything until it hits the letter "z" but do not include z
  • 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-17T15:59:46+00:00Added an answer on May 17, 2026 at 3:59 pm

    The explicit way of saying “search until X but not including X” is:

    (?:(?!X).)*
    

    where X can be any regular expression.

    In your case, though, this might be overkill – here the easiest way would be

    [^z]*
    

    This will match anything except z and therefore stop right before the next z.

    So .*?quick[^z]* will match The quick fox jumps over the la.

    However, as soon as you have more than one simple letter to look out for, (?:(?!X).)* comes into play, for example

    (?:(?!lazy).)* – match anything until the start of the word lazy.

    This is using a lookahead assertion, more specifically a negative lookahead.

    .*?quick(?:(?!lazy).)* will match The quick fox jumps over the.

    Explanation:

    (?:        # Match the following but do not capture it:
     (?!lazy)  # (first assert that it's not possible to match "lazy" here
     .         # then match any character
    )*         # end of group, zero or more repetitions.
    

    Furthermore, when searching for keywords, you might want to surround them with word boundary anchors: \bfox\b will only match the complete word fox but not the fox in foxy.

    Note

    If the text to be matched can also include linebreaks, you will need to set the “dot matches all” option of your regex engine. Usually, you can achieve that by prepending (?s) to the regex, but that doesn’t work in all regex engines (notably JavaScript).

    Alternative solution:

    In many cases, you can also use a simpler, more readable solution that uses a lazy quantifier. By adding a ? to the * quantifier, it will try to match as few characters as possible from the current position:

    .*?(?=(?:X)|$)
    

    will match any number of characters, stopping right before X (which can be any regex) or the end of the string (if X doesn’t match). You may also need to set the “dot matches all” option for this to work. (Note: I added a non-capturing group around X in order to reliably isolate it from the alternation)

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

Sidebar

Related Questions

I learned a lot of Perl RegEx syntax rules, but probably the only way
I am trying to implement the following regex search found on golfscript syntax page
I tried to make regex syntax for that but I failed. I have 2
Is it possible to perform a named-group match in Perl's regex syntax as with
I read this PHP RegEx page , but either I'm missing something, misreading something,
What is the regex syntax to use part of a matched expression in the
I'm looking for a decent tool that can do search and replace over multiple
I am new to the RegEx and i want to be able to search
How can I create an XPath expression that works like a regex would, so
I need to use a regex pattern , but what is the right php

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.