Splunk Search

What is the most efficient way to extract user name from my sample Message fields?

smudge797
Path Finder

What's the most efficient way to extract the user name from these messages:

Message=Self-service Plug-in started (user=DOMAINX\a123456)
Message=Self-service Plug-in started (user=DOMAINY\c123456)

Thanks

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | rex field=Message "\(user=(?<user>[^\)]+)"

View solution in original post

ddrillic
Ultra Champion
\\(?<user>(\w|\d+)*) should do it...
0 Karma

smudge797
Path Finder

Error in 'rex' command: Encountered the following error while compiling the regex '(?(\w|\d+)*)': Regex: unmatched parentheses

0 Karma

ddrillic
Ultra Champion

right ; -)

| rex  field=data "\\\(?<user>(\w|\d)*)"

three slashes - the editors mistreat them ....

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=Message "\(user=(?<user>[^\)]+)"

View solution in original post

smudge797
Path Finder

Nice,

user="DOMAINY\L123456"
Can we drop the domain or separate it?

0 Karma

woodcock
Esteemed Legend

Like this:

 ... | rex field=Message "\(user=(?<domain>[^\\\]+)\\\(?<user>[^\)]+)"
0 Karma

smudge797
Path Finder

Nice thanks!

0 Karma

ppablo
Community Manager
Community Manager

Hi @smudge797

Glad you found a solution through @woodcock and gave him an upvote, but please don't forget to click "Accept" directly below his answer to resolve the question. Thanks!

0 Karma

smudge797
Path Finder

Done!

Thanks.

richgalloway
SplunkTrust
SplunkTrust

I'm not sure if it's the most efficient, but it's one of the simplest.

... | rex field=Message "\\(?<userName>[^\)]*)" | ...
---
If this reply helps you, an upvote would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The leading backslash needs to be escaped. Otherwise, it escapes the left paren.

---
If this reply helps you, an upvote would be appreciated.
0 Karma

smudge797
Path Finder

Error in 'rex' command: Encountered the following error while compiling the regex '\(?[^\)]*)': Regex: unmatched parentheses

0 Karma

jmallorquin
Builder

Hi,

props.conf

[<<sourcetype>>>]
.
.
.

    EXTRACT-user = \\(?<user_wo_domain>[^\)]+)\)$

Hope i help you

0 Karma
.conf21 Now Fully Virtual!
Register for FREE Today!

We've made .conf21 totally virtual and totally FREE! Our completely online experience will run from 10/19 through 10/20 with some additional events, too!