# Grok match to last index unti begin of UserAgent

**URL:** <https://discuss.elastic.co/t/grok-match-to-last-index-unti-begin-of-useragent/88189>\
**Category:** Logstash\
**Created:** [June 4, 2017, 1:00pm UTC](https://discuss.elastic.co/t/grok-match-to-last-index-unti-begin-of-useragent/88189 "2017-06-04T13:00:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaleid\_lund](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@khaleid\_lund](https://discuss.elastic.co/u/khaleid_lund)\
**Post date:** [June 4, 2017, 1:00pm UTC](https://discuss.elastic.co/t/grok-match-to-last-index-unti-begin-of-useragent/88189/1 "2017-06-04T13:00:08Z")

</div>

Hi all  
I have message

"sid-cmascioieiow89322&New\*Sou,th%20Skvn%20and%20ir&o,n%20Age,Mozilla/5.0 (Linux; Android 6.0; CHM-U01 Build/HonorCHM-U01) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36"

and the pattern  
"(?[^&]_)&(?[^,]_),%{GREEDYDATA:User\_Agent}"

the problem is p2 some time contains zero or one or more then one comma i want to match to the last comma before UserAgent because UserAgent some time contains comma

now

{  
"p1": [  
"sid-cmascioieiow89322"  
],  
"p2": [  
"New\*Sou"  
],  
"User\_Agent": [  
"th%20Skvn%20and%20iro,n%20Age,Mozilla/5.0 (Linux; Android 6.0; CHM-U01 Build/HonorCHM-U01) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36"  
]  
}  
I want like this

{  
"p1": [  
"sid-cmascioieiow89322"  
],  
"p2": [  
"New\*Sou,th%20Skvn%20and%20ir&o,n%20Age"  
],  
"User\_Agent": [  
"Mozilla/5.0 (Linux; Android 6.0; CHM-U01 Build/HonorCHM-U01) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36"  
]  
}

thank you for help

---

<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 2, 2017, 1:00pm UTC](https://discuss.elastic.co/t/grok-match-to-last-index-unti-begin-of-useragent/88189/2 "2017-07-02T13:00:13Z")

</div>

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