# Fix grok pattern

**URL:** <https://discuss.elastic.co/t/fix-grok-pattern/89286>\
**Category:** Logstash\
**Created:** [June 14, 2017, 12:32am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286 "2017-06-14T00:32:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibrahimsharaf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ibrahimsharaf/32/17304_2.png) [@ibrahimsharaf](https://discuss.elastic.co/u/ibrahimsharaf)\
**Post date:** [June 14, 2017, 12:32am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/1 "2017-06-14T00:32:45Z")

</div>

Hello, I've a logfile which contains a line like this:  
`2017-05-01 07:41:25 [scraper.py] DEBUG: Scraped from <200 https://www.diwanegypt.com/>{'category_ar': u'biographies'}`

I want to extract the url into a variable called scraped url from this line, I tried this regex `(?<=<).*(?=>)` but it didn't work, any ideas?

---

<div class="post-metadata">

**Author:** ![ibrahimsharaf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ibrahimsharaf/32/17304_2.png) [@ibrahimsharaf](https://discuss.elastic.co/u/ibrahimsharaf)\
**Post date:** [June 14, 2017, 12:35am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/2 "2017-06-14T00:35:44Z")

</div>

I also tried this `%{TIMESTAMP_ISO8601} %{NOTSPACE} DEBUG: Scraped from <200 %{GREEDYDATA:scraped_url}`  
output:

> "scraped\_url":  
> [  
> "[https://www.diwanegypt.com/](https://www.diwanegypt.com/)\>{'category\_ar': u'biographies'}"  
> ]

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 14, 2017, 5:38am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/3 "2017-06-14T05:38:42Z")

</div>

Please show the result of a `stdout { codec => rubydebug }` output so we can see exactly what the result is.

---

<div class="post-metadata">

**Author:** ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)\
**Post date:** [June 14, 2017, 7:27am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/4 "2017-06-14T07:27:23Z")

</div>

You could try something like:

```
if [message] =~ /.*Scraped\sfrom.*/ {
    grok {
        match => { "message" => ".*\<\d{3}\s(?<scraped_url>.*(?=\/\>))" }
    }
}
```

---

<div class="post-metadata">

**Author:** ![ibrahimsharaf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ibrahimsharaf/32/17304_2.png) [@ibrahimsharaf](https://discuss.elastic.co/u/ibrahimsharaf)\
**Post date:** [June 14, 2017, 10:44am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/5 "2017-06-14T10:44:22Z")

</div>

Thank you guys, @Kryten's solution is working.

---

<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 12, 2017, 10:44am UTC](https://discuss.elastic.co/t/fix-grok-pattern/89286/6 "2017-07-12T10:44:30Z")

</div>

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