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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:38:29+00:00 2026-05-22T12:38:29+00:00

Given this string: var str = ‘A1=B2;C3,D0*E9+F6-‘; I would like to retrieve the substring

  • 0

Given this string:

var str = 'A1=B2;C3,D0*E9+F6-';

I would like to retrieve the substring that goes from the beginning of the string up to 'D0*' (excluding), in this case:

'A1=B2;C3,'

I know how to achieve this using the combination of the substr and indexOf methods:

str.substr(0, str.indexOf('D0*'))

Live demo: http://jsfiddle.net/simevidas/XSu22/

However, this is obviously not the best solution since it contains a redundancy (the str name has to be written twice). This redundancy can be avoided by using the match method together with a regular expression that captures the substring:

str.match(/???/)[1]

Which regular expression literal do we have to pass into match to ensure that the correct substring is returned?

My guess is this: /(.*)D0\*/ (and that works), but my experience with regular expressions is rather limited, so I’m going to need a confirmation…

  • 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-22T12:38:30+00:00Added an answer on May 22, 2026 at 12:38 pm

    Try this:

    /(.*?)D0\*/.exec(str)[1]
    

    Or:

    str.match(/(.*?)D0\*/)[1]
    

    DEMO HERE

    ? directly following a quantifier makes the quantifier non-greedy (makes it match minimum instead of maximum of the interval defined).
    Here’s where that’s from

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

Sidebar

Related Questions

Given this generic serialization code: public virtual string Serialize(System.Text.Encoding encoding) { System.IO.StreamReader streamReader =
I have a TextArea component called labels that will be populated by Strings in
google.visualization.events.addListener( geomap, regionClick, function(e) { console.log(e[region]); console.log(data.getValue(e[region],1)); }); I use this code to see
I'm getting a JSON response from the server and i have to loop through
I'm creating an AIR project in flash and populated a list with files referenced
Playing around with Dapper, I'm quite pleased with the results so far - intriguing!
I'm playing around with EF Code First and need some help. A User can
I have started to test an application on Honeycomb and get the following error
Basically, I'm curious on how to get hold of new BigDecimal(Double.toString(d)) without going through

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.