Splunk Search

creating a new field using Regex

mr_t2083
Explorer

how do you create a field using regex with the following example below
for example

exsamplefield=cpe:/o:microsoft:windows

I would like to extract microsoft from the above field?

What would be proper regex used to extract this?

Tags (1)
0 Karma

macadminrohit
Contributor

cpe:\/(a|o):(?\w+):.*

microsoft will be captured in the named group

For testing, try www.regex101.com

0 Karma

macadminrohit
Contributor
cpe:\/(a|o):(?<fieldname>\w+):.*
0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=exsamplefield="^(?:[^:]*:){2}(?<YourNameHere>[^:]+)"

somesoni2
SplunkTrust
SplunkTrust

Will it always be in same position?

mr_t2083
Explorer

same position yes but not same letter, this is another example " cpe:/a:microsoft:malicious_software_removal_tool" so I'm looking for a way to distinguish between cpe:/o and cpe:/a

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Have you tried any of solution below? They both should work for you. If you want little more specific regex based on your data, you can try this cpe\:\/(o|a)\:(?<YourFieldName>[^\:]+). (Basically look for either cpe:/a: or cpe:/o: and capture everything after that till next colon)

0 Karma

PowerPacked
Builder

Hi mr_t2083

Please use this REX,

am uploading pic as this page will try to remove some characters from REX if directly posted.
alt text

& if you want to apply Rex to field itself, refer to this second pic

alt text

Thanks

xpac
SplunkTrust
SplunkTrust

To build a proper regex, you need to describe your data properly, it has to have some reliable characteristics.
With your example above, multiple characteristics are possible, but without further example data it's hard to find those similarities.

This is an example: ^[^:]+:[^:]+:(?<yourfield>[^:]+:)
This one would assume that there is always to parts in that field, seperated by :, and the value you want to extract is between the second and third :. If that's true - here's your regex 😉

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...