Splunk Search

Use named backreference in the subsequent rex command

Murali2888
Communicator

Hi All,

Can you let me know how we can use a named backreference in the subsequent rex command? That is pass the value of the named backreference to the next rex command.

I am trying something like below which is not providing the desired result.

rex "<tag1>(?P<NamedField1>[^<]+" | rex "<tag2>?(P=NamedField1)</tag2><tag3>(?P<NamedField2>)" | table NamedField2

If someone could point out some documentation around this that would be very helpful.

0 Karma

maciep
Champion

Not exactly what you're asking, but you can use \n to represent a previously captured group in the same rex command. So in your case, something like

rex "<tag1>(?P<NamedField1>[^<]+").+<tag2>\1</tag2><tag3>(?P<NamedField2>)" 

Although I'm pretty sure i found a way to substitute field names in the rex too, but don't remember and could be mistaken.

0 Karma

Murali2888
Communicator

Thanks maciep.

I had this option, but unfortunately the xml structure is quite redundant and complex which would not allow using a single rex command. Nevertheless, I had found some workaround with eval command.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...