# Matching field to a single digit number

**URL:** <https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405>\
**Category:** Logstash\
**Created:** [November 26, 2019, 2:28am UTC](https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405 "2019-11-26T02:28:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreliable](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sreliable](https://discuss.elastic.co/u/sreliable)\
**Post date:** [November 26, 2019, 2:28am UTC](https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405/1 "2019-11-26T02:28:54Z")

</div>

I have a field which contains strings like "0","1"..."10","11"..."23".  
How do I get an if statement where I take only fields which match single digits? ie. "0","1"...."9"?

Currently what I have is this:

```
if [tmHour] =~ /[0-9]{1}/ {
    *code here*
}

```

But it still matches everything.

---

<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:** [November 26, 2019, 1:45pm UTC](https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405/2 "2019-11-26T13:45:56Z")

</div>

You would need to anchor it, otherwise it will match the first digit of a multi-digit string.

```
if [tmHour] =~ /^[0-9]$/
```

---

<div class="post-metadata">

**Author:** ![sreliable](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sreliable](https://discuss.elastic.co/u/sreliable)\
**Post date:** [November 27, 2019, 6:06am UTC](https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405/3 "2019-11-27T06:06:12Z")

</div>

Thank you @Badger!  
Your solution works just fine.

---

<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:** [December 25, 2019, 6:06am UTC](https://discuss.elastic.co/t/matching-field-to-a-single-digit-number/209405/4 "2019-12-25T06:06:12Z")

</div>

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