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 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

I want to use VBA to extract a unique, ordered list, subject to conditions
There is quite often situation when you need to execute INSERT, UPDATE or DELETE
I am evaluating certain conditions sent by a jsp page and sending the ajax
Using Zend Framework, is there a way to pass multiple conditions to an update
I have this below code(this is a sample, there are many more other conditions
Conditions: Windows 98 SE WMI not available I have code that looks like this,
How do I set conditions to affect all images within my webpage (via CSS)
How can i make conditions on sending emails to users based on date which
what sort of conditions can we use for branching in jinja2? I mean can
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.