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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:08:06+00:00 2026-05-22T16:08:06+00:00

I have this: var str = A123B234C456; I need to split it into comma-separated

  • 0

I have this:

var str = A123B234C456;

I need to split it into comma-separated chunks to return something like this:

A,123,B,234,c,456

I thought a regular expression would be best for this, but I keep getting stuck. Essentially, I tried to do a string replace, but you cannot use a regular expression in the second argument.

I would love to keep it simple and clean and do something like this, but it does not work:

str = str.replace(/[\d]+/, ","+/[\d]+/);

But in the real world that would be too simple.

Is it possible?

  • 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-22T16:08:07+00:00Added an answer on May 22, 2026 at 4:08 pm

    It may be more sensible to match the characters and then join them:

    str = str.match(/(\d+|[^\d]+)/g).join(',');
    

    But don’t omit the quotes when you define the string:

    var str = 'A123B234C456';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have something like this: var str = 0123; var i = 0;
input is a string (var str) something like this: <<hello there//abcd//1234>> I want to
I have this code: var str = $(#datepicker).datepicker(getDate); var datestr = str.toString().split( ); switch(datestr[1])
I have a string like this: var str = I'm a very^ we!rd* Str!ng.;
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I have this var in my code: var href = $(this).attr('href'), str = href.split('/').slice(-2,-1)[0];
I have a string like this as below var str = '101,1245###company1-|102,1221###company2-|102,1651###company3-|-'; Can we
I have string like this var str = #it itA itB _ #et etA
I have this: var date = new DateTime(2009, 12, 5); ... ... and need
I have a comma-separated string that I want to convert into an array, so

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.