Splunk Search

Another Regex Question

kwkeefer
Explorer

I'm trying to rex out a new field from the message.Exception field. What I'm trying to extract is in the brackets below (the brackets are not actually in the Splunk message):

com.companyname.companyinitials.[servicename.servicenameApplication].main

I need to make it so that the regex looks for something that starts with "com.companyname.companyinitials." and ends with ".main" as the message.Exceptions field also contains something that starts with "com.companyname.companyinitials." but it is unrelated to the field I'm trying to extract.

I've tried to hack together some regex based on my google searching (I'm decent at regex for python but I can't figure out Splunk's for some reason) and I'm not doing very well. Here's what I have so far (which isn't working obviously):

...query... | rex field=message.Exception "com\.companyname\.companyinitials\.(?<Service>[^(main)]"

I'm getting a new field, but it only contains one character, and it seems to be the character for the other unrelated line that starts with the same "com.companyname.companyinitials." ...

I appreciate any help - sorry for being bad at regex..

0 Karma
1 Solution

gokadroid
Motivator

How about trying this to save the required text in field requiredText

...query... | rex field=message.Exception "com\.companyname\.companyinitials\.(?<requiredText>[\S]+)\.main"

See extraction here

View solution in original post

gokadroid
Motivator

How about trying this to save the required text in field requiredText

...query... | rex field=message.Exception "com\.companyname\.companyinitials\.(?<requiredText>[\S]+)\.main"

See extraction here

mayurr98
Super Champion

hey Try this run anywhere search

| makeresults 
| eval message.Exception="com.companyname.companyinitials.servicename.servicenameApplication.main" 
| rex field="message.Exception" "com\.companyname\.companyinitials\.(?<Service>.*)\.main"

In your environment, you should write

...query... | rex field=message.Exception "message.Exception" "com\.companyname\.companyinitials\.(?<Service>.*)\.main"

let me know if this helps!

0 Karma

493669
Super Champion

Try this:

|rex field="message.Exception"  "com\.companyname\.companyinitials\.(?<serviceName>\w+\.\w+)\.main"

gokadroid
Motivator

This regex has the flaw that if there are more than two elements in the requirement stated in question and I quote I need to make it so that the regex looks for something that starts with "com.companyname.companyinitials." and ends with ".main" as the message this will fail for sure.
It will fail for something like this with three elements between com.companyname.companyinitials and .main:

com.companyname.companyinitials.servicename.servicenameApplication.abc.main

0 Karma

adonio
Ultra Champion

hope i understood you correctly,
give this a try:

 ... search ... | rex field="message.Exception" "com\.companyname\.companyinitials.\[(?<serviceName>\w+)\.(?<serviceNameAplication>\w+)]\.main"

extracting two fields: serviceName and serviceNameApllication
if you want one field:

 ... search ... | rex field="message.Exception" "com\.companyname\.companyinitials.\[(?<serviceName>\w+\.\w+)]\.main"

hope it helps

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...