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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:28:12+00:00 2026-06-06T12:28:12+00:00

Given a string such as: 23,234,456 first second third How can I split string

  • 0

Given a string such as:

23,234,456 first second third

How can I split string this into two parts, where part 1 contains the number at the beginning and part 2 contains the rest—but only if the string STARTS with a number, and the number can be comma-separated or not? In other words, I want two results: 23,234,456 and first second third. If there’s a number in that string that isn’t part of the first number then it should be in the second result.

My best stab at this so far, to grab the number at the beginning, is something like this:

^[0-9]+(,[0-9]{3})*

Which seems to grab a comma-separated or non-comma-separated number that starts the line. However, when I run this in the Javascript console I get not only the full number, but also a match on just the last 3 digits with their preceeding ,. (e.g. 23,234,456 and ,456).

As for getting the rest into another var I’m having trouble. I tried working with \b, etc., but I think I must be missing something fundamental about grabbing the rest of the line.

I’m doing this in Javascript in case it matters.

More examples of what to match and what not to match.

2 one two three should return 2 and one two three

2345 one two three should return 2345 and one two three

2 one 2 three should return 2 and one 2 three

2,234 one two 3,000 should return 2,234 and one two 3,000

The space between parts 1 and two could be included in the beginning of part 2.

  • 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-06T12:28:14+00:00Added an answer on June 6, 2026 at 12:28 pm

    You need to use capturing groups for both first and rest. Try this regex:

    ^(\d+(?:,\d+)*)\s+(.*)
    

    Now the group 1 is your comma separated numbers and group 2 is the rest. \s+ eats the whitespace in between. (at least 1 required).

    And of course, if the regex does not match at all, then it does not start with a number or comma separated list of numbers, followed by one whitespace character or more.

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

Sidebar

Related Questions

Given a string such as: new/path - path/path/03 - filename.ext, how can I use
Given a string such as abc-def-ghi-jkl . Can the sed command extract the substring
Using PHP, given a string such as: this is a <strong>string</strong> ; I need
Given a string such as this: Bob Smith <bobsmith@gmail.com>, Jones, Rich A. <richjones@gmail.com> I
Given a font CSS string such as this: font:italic bold 12px/30px Georgia, serif; or
This is an interview question. Given a string such as: 123456abcdef consisting of n/2
Possible Duplicate: In PHP given a month string such as “November” how can I
Given a string such as 8584320342564023450211233923239923239110001012346596 , how can get all consecutive 4 digit
Alright, Currently, if given a string like such: A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8 I am using this: child
Given a string such as: a:2:{i:0;s:1:1;i:1;s:1:2;} I want to find every integer within quotes

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.