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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:35:22+00:00 2026-06-11T21:35:22+00:00

For instance, I am using a simple regex to match everything before the first

  • 0

For instance, I am using a simple regex to match everything before the first space:

var str = '14:00:00 GMT';
str.match(/(.*?)\s/)[0]; //Returns '14:00:00 ' note the space at the end

To avoid this I can do this:

str.match(/(.*?)\s/)[0].replace(' ', '');

But is there a better way? Can I just not include the space in the regex? Another examle is finding something between 2 characters. Say I want to find the 00 in the middle of the above string.

str.match(/:(.*?):/)[0]; //Returns :00: but I want 00
str.match(/:(.*?):/)[0].replace(':', ''); //Fixes it, but again...is there a better way?
  • 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-11T21:35:25+00:00Added an answer on June 11, 2026 at 9:35 pm

    I think you just need to change the index from 0 to 1 like this:

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

    0 means the whole matched string, and 1 means the first group, which is exactly what you want.

    @codaddict give another solution.

    str.match(/(.*?)(?=\s)/)[0]
    

    (?=\s) means lookahead but not consume whitespace, so the whole matched string is ’14:00:00′ but without whitespace.

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

Sidebar

Related Questions

At the moment I'm developing using a simple editor, putty, and a VirtualBox instance
I am using a simple regex to replace break tags with newlines: br_regex =
I am trying to pass the XML code below, in the first instance using
I have a simple query to a Solr instance using SolrNet, But for some
So I create an instance using one of the Public AMI EBS Ubuntu flavors.
I am trying to access an ec2 instance using a different (mac) computer. In
I was deploying an Azure instance using Visual Studio (2010) and i get this:
i load a class using Class.forName(klassname,false,loader) After this i create an instance using klass.newInstance();
I'm enumerating all databases of an SQL Server 2005 instance using SMO like as
I need to import a database into a SQL Server instance using a batch

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.