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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:06:45+00:00 2026-06-01T02:06:45+00:00

I have this string: my $string = 2, 16, \d4,d6\, \d20,d22\, [0]; and I

  • 0

I have this string:

my $string = "2, 16, \"d4,d6\", \"d20,d22\", [0]";

and I use split like that:

my @arglist = split(/,/, $string);

The problem is that originally I never had these commas embedded in quoted string and now I have and I need to update that split regex to handle that case.

Please, absolutely don’t mention anything other than what I ask. I’ve searched enough and more than half answers are noise about how complex CSV parsing is etc etc. I didn’t write that script that I need fix and all I want is to modify that single line that does the split, so it should be simple regex that does that. There will not be any updates and the text that it splits will be this only:

CHROMA_MC_X \width, \align, "d4,d5,d6,d7", "d20,d21,d22,d23"
CHROMA_MC_X \width, \align, "d4,d6", "d20,d22", [0]
CHROMA_MC_X \width, \align, "d4,d6", "d20,d22", [0]

EDIT
The answer by Birei was enough to start from. I ended up cooking this regex that perfectly handles my case:

my @arglist = $3 =~ m/(?:(?<=")[^"]*(?=(?:\s*"\s*,|\s*"\s*$)))|(?<=,)(?:[^",]*(?=(?:\s*,|\s*$)))|(?<=^)(?:[^",]+(?=(?:\s*,|\s*$)))|(?<=^)(?:[^",]*(?=(?:\s*,)))/g;

It looks messy, but it does exactly what I need. It matches quoted lists with comas and returns them without the quote marks, there were some issues with empty args that could be present and this regex is messy because it just handles these cases as well and avoids that error with variable length lookbehind that isn’t implemented in perl regex.

What I don’t get: What’s the reason for all these downvotes, am I under attack of some perl gurus who think I don’t know what I need and what I ask for?! I have tool that does some asm preprocessing and all I needed is to handle a few cases. THAT’S IT. Thanks for help.

  • 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-01T02:06:46+00:00Added an answer on June 1, 2026 at 2:06 am

    One way:

    Content of script.pl:

    use warnings;
    use strict;
    
    my $string = "2, 16, \"d4,d6\", \"d20,d22\", [0]";
    my @arglist = $string =~ m/("[^"]+"|[^,]+)(?:,\s*)?/g;
    printf qq[%s\n], join qq[\n], @arglist;
    

    Run it like:

    perl script.pl
    

    With following result:

    2
    16
    "d4,d6"
    "d20,d22"
    [0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string: a\,bcde,fgh,ijk\,lmno,pqrst\,uv I need a JavaScript function that will split the
I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I have this string: "My name is Marco and I'm from Italy" I'd like
I have this string that has illegal chars that I want to remove but
i have this string: i[TAB]like[TAB]Stackoverflow and i need to get this: i like Stackoverflow
I have this String: player.login name=username;x=52;y=406 how would I be able to split it
I have this string string sx=(colorIndex=3)(font.family=Helvetica)(font.bold=1); and am splitting it with string [] ss=sx.Split(new
I have this string that I get back from Adobe Presenter 7. It's called
I have this string : myString=Citt&agrave; and I'd like to display correctly (as Città)
I have this string s that is formatted in this way. I want to

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.