Help for this page

Select Code to Download


  1. or download this
    $s = 'a,b,"hey, you","str1, str2, str3",end';
    push @fields, $1 while $s =~ /("[^"]+"|[^",]+)(?:,|$)/g;
    print "$_\n" for @fields;
    
  2. or download this
    $s = 'a,b,"hey, you","str1, str2, str3",end';
    @fields = $s =~ /("[^"]+"|[^,]+)(?:,|$)/g;  # Use +, not *, or you get
    + a blank element
    print "$_\n" for @fields;
    
  3. or download this
    a
    b
    "hey, you"
    "str1, str2, str3"
    end