# Split a string by commas but ignore commas within double-quotes？

**URL:** https://discuss.elastic.co/t/split-a-string-by-commas-but-ignore-commas-within-double-quotes/136471
**Category:** Logstash
**Created:** [June 19, 2018, 10:43am UTC](https://discuss.elastic.co/t/split-a-string-by-commas-but-ignore-commas-within-double-quotes/136471 "2018-06-19T10:43:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Huang\_Gyo](https://avatars.discourse-cdn.com/v4/letter/h/df788c/32.png) [@Huang\_Gyo](https://discuss.elastic.co/u/Huang_Gyo)
#### Post date: [June 19, 2018, 10:43am UTC](https://discuss.elastic.co/t/split-a-string-by-commas-but-ignore-commas-within-double-quotes/136471/1 "2018-06-19T10:43:35Z")

</div>

For example, my log is like:  
2018-06-12T10:58:19.617Z, , "test,test", BJSGEXMBX12, , , SMTP, HARECEIVE, 41661182775666

How to split it by "," but ignore the "," in "test,test"? Thanks!

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [June 19, 2018, 1:13pm UTC](https://discuss.elastic.co/t/split-a-string-by-commas-but-ignore-commas-within-double-quotes/136471/2 "2018-06-19T13:13:17Z")

</div>

> [@Huang\_Gyo](#):
>
> 2018-06-12T10:58:19.617Z, , "test,test", BJSGEXMBX12, , , SMTP, HARECEIVE, 41661182775666

A csv filter would parse that, except that you have a space at the beginning of the field. If a field is quoted then the entire field has to be quoted. It has to be comma, double quote, field value, double quote, comma, with no spaces between the commas and the double quotes. Depending on what your data looks like you might be able to mutate+gsub the space away before using csv {}.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 17, 2018, 1:13pm UTC](https://discuss.elastic.co/t/split-a-string-by-commas-but-ignore-commas-within-double-quotes/136471/3 "2018-07-17T13:13:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
