# Extract timestamp from filename

**URL:** https://discuss.elastic.co/t/extract-timestamp-from-filename/56135
**Category:** Logstash
**Created:** [July 21, 2016, 8:01pm UTC](https://discuss.elastic.co/t/extract-timestamp-from-filename/56135 "2016-07-21T20:01:47Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [July 22, 2016, 8:13am UTC](https://discuss.elastic.co/t/extract-timestamp-from-filename/56135/4 "2016-07-22T08:13:11Z")

</div>

Always format regular expressions as code. If you look closely at your post you'll note that it doesn't represent reality. All underscores have disappeared.

Unsurprisingly, capturing a time works the same way as capturing a date. I suggest the following expression for capturing the whole timestamp string (including the square brackets):

```
(?<timestamp>\[%{YEAR}_%{MONTHNUM}_%{MONTHDAY}\]\[%{HOUR}_%{MINUTE}_%{SECOND}\])

```

This string can then be fed to the date filter.

---

_[View the full topic](https://discuss.elastic.co/t/extract-timestamp-from-filename/56135)._
