- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to use regex command to match a certain amount of characters in a field?
showard22
New Member
03-20-2017
03:47 PM
I want to use Splunk to match on a field name for accounts with exactly 4 characters, all numbers and letters.
I keep trying:
index=corp sourcetype=importantlogs | fields Account EventType | regex Account="[a-zA-Z0-9]{4}"
I feel like I'm overlooking something super simple and I've been stuck on this for a few hours. Any outsider thoughts?
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

DalJeanis
Legend
03-20-2017
09:03 PM
woodcock has a good answer, once you change the period to a more limited character class (\w is the simplest) For the same effect of keeping only accounts that are exactly 4 "word" characters, you could also use...
| where like(Account, "^\w{4}$"
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

woodcock
Esteemed Legend
03-20-2017
06:23 PM
You did not anchor it; try this:
index=corp sourcetype=importantlogs | fields Account EventType | regex Account="^.{4}$"
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

DalJeanis
Legend
03-20-2017
08:58 PM
Need a smaller character class, only letters and numbers.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

woodcock
Esteemed Legend
03-21-2017
07:25 AM
A simpler match character is more efficient and worth the infinitesimally small risk of a false positive.
