Splunk Search

Error in 'rex' command: Regex: quantifier does not follow a repeatable item

AshimaE
Explorer

On using regex one by one to replace two types of strings its is giving the following error. Also while using the replace twice it is giving the error
Error in 'rex' command: Regex: quantifier does not follow a repeatable item

Any way to work around this.
My query looks like the following

index=abc sourcetype=def "pushed to the connector." | rex field=message "Message to \'(?<push>.*)\' pushed to the connector." | rex field=push mode=sed "s/ //g" | rex field=push mode=sed "s/+//g" | table message push

And for replace it is

index=abc sourcetype=def "pushed to the connector." | rex field=message "Message to \'(?<push>.*)\' pushed to the connector." |  eval final=trim(replace(push," ","")) | eval final2=replace(final,"+","") | table message push final final2

How to work around this issue.

0 Karma

niketn
Legend

@AshimaE, you need to escape plus sign in second replace with slash. Please refer to the modifications below

index=abc sourcetype=def "pushed to the connector." 
| rex field=message "Message to \'(?<push>[^'].*)\' pushed to the connector." 
| eval final=replace(replace(push," ",""),"\+","") 
| table message push final
  • You dont need trim() since replace is doing the same.
  • Replace can be cascaded.
  • For RegEx I have added [^'] which says find everything (refer to regex101.com for details) except single quote which currently marks the end of extracted field pushed.
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

niketn
Legend

@AshimaE, can you please test and confirm whether the suggested change worked for you?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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