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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:08:19+00:00 2026-06-04T11:08:19+00:00

I have a string like following var str=A,B,C,E,’F,G,bb’,H,’I9,I8′,J,K I’d like to split the string

  • 0

I have a string like following

var str="A,B,C,E,'F,G,bb',H,'I9,I8',J,K"

I’d like to split the string on commas. However, in the case where something is inside single quotation marks, I need it to both ignore commas as following.

 A
 B
 C
 E
 F,G,bb
 H
 I9,I8
 J
 K
  • 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-04T11:08:21+00:00Added an answer on June 4, 2026 at 11:08 am
    > str.match(/('[^']+'|[^,]+)/g)
    ["A", "B", "C", "E", "'F,G,bb'", "H", "'I9,I8'", "J", "K"]
    

    Though you requested this, you may not accounted for corner-cases where for example:

    • 'bob\'s' is a string where ' is escaped
    • a,',c
    • a,,b
    • a,b,
    • ,a,b
    • a,b,'
    • ',a,b
    • ',a,b,c,'

    Some of the above are handled correctly by this; others are not. I highly recommend that people use a library that has thought this through, to avoid things such as security vulnerabilities or subtle bugs, now or in the future (if you expand your code, or if other people use it).


    Explanation of the RegEx:

    • ('[^']+'|[^,]+) – means match either '[^']+' or [^,]+
    • '[^']+' means quote…one-or-more non-quotes…quote.
    • [^,]+ means one-or-more non-commas

    Note: by consuming the quoted string before the unquoted string, we make the parsing of the unquoted string case easier.

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

Sidebar

Related Questions

I have a string like the following: String str = 4*5; Now I have
Supposed I have the following string: string str = <tag>text</tag>; And I would like
For example I have a string that looks like the following: var example_string =
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
I have a string like the following: $string = <paragraph>apples are red...</paragraph> <paragraph>john is
I have a string like the following: <br><b>224h / 15.45 verbuchte Stunden</b> I want
Assume we have a string like the following : ,34,23,4,5,634,23,12,5,4,3,1234,23,54,,,,,,,123,43,2,3,4,5,3424,,,,,,,,123,,,1234,,,,,,,45,,,56 How can we convert
I have a string that is formatted like the following: ... {{word1}} {{word2}} ....
I have the following String First Last <first.last@email.com> I would like to extract first.last
Hi guys i have the following string &|L1|L2|L3|& I would like to extract L1

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.