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

  • Home
  • SEARCH
  • 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 4244168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:40:23+00:00 2026-05-21T03:40:23+00:00

Conditions updated There is often a situation where you want to extract a substring

  • 0

Conditions updated

There is often a situation where you want to extract a substring upto (immediately before) certain characters. For example, suppose you have a text that:

  • Does not start with a semicolon or a period,
  • Contains several sentences,
  • Does not contain any “\n”, and
  • Ends with a period,

and you want to extract the sequence from the start upto the closest semicolon or period. Two strategies come to mind:

  1. /[^;.]*/
  2. /.*?[;.]/

I do either of these quite randomly, with slight preference to the second strategy, and also see both ways in other people’s code. Which is the better way? Is there a clear reason to prefer one over the other, or are there better ways? I personally feel, efficiency aside, that negating something (as with [^]) is conceptually more complex than not doing it. But efficiency may also be a good reason to chose one over the other.

  • 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-21T03:40:23+00:00Added an answer on May 21, 2026 at 3:40 am

    I came up with my answer. The two regexes in my question were actually not expressing the same thing. And the better approach depends on what you want.

    1. If you want a match up to and including a certain character, then using

      /.*?[;.]/

    is simpler.

    1. If you want a match up to right before (excluding) a certain character, then you should use:

      /[^;.]*/

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

Sidebar

Related Questions

There are certain conditions that can cause stack overflows on an x86 Linux system:
There is quite often situation when you need to execute INSERT, UPDATE or DELETE
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
The situation is like this: there is a continuous loop, that updates some values.
Under some conditions, I want to make a celery task fail from within that
Code is read more often then updated. Writing more readable code is better than
Conditions: Windows 98 SE WMI not available I have code that looks like this,
Sometimes I break long conditions in if s onto several lines. The most obvious
The number of query conditions is determined by user selections at runtime, ie var
Since I cannot put conditions on elements in a component, I have to separate

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.