0

How do I escape these kinds of special character in curl. The below is passed in the query part. I am trying to query splunk data and this is reg expression with rex command. Without the below characters it works fine. But I need this to be part of the query.

(?i)^(?:[^-]*-){}\s+\d+

I tried giving -g to stop globbing. But that doesn't work. Is there any simpler way to do this. I am passing --data urlencode in curl so encoding is automatically taken care.

Deb
  • 193
  • 1
  • 3
  • 20
  • See if the help in http://stackoverflow.com/questions/102049/how-do-i-escape-the-wildcard-asterisk-character-in-bash will help you. Since I'm suspecting this is a shell problem, and not a curl problem. – Larry Shatzer Sep 07 '15 at 14:29
  • Can you try adding your curl script to a .sh file, and running it? – Shakeel Sep 08 '15 at 17:06

1 Answers1

1

I recently encountered the exact same problem statement. Splunk was having an issue with my regex when it contained [ or ] characters. I was also using curl, and I was sending my search query with curl's -d parameter for post data. I tried several variations of encoding of the brackets (escaping them, percent-encoding them, etc.), but to no avail.

The solution in my case was to use the --data-urlencode parameter instead of the --data parameter.

From the curl help:

 $ curl --help | grep "\-\-data"  
  -d/--data <data>   HTTP POST data (H)
     --data-ascii <data>  HTTP POST ASCII data (H)
     --data-binary <data> HTTP POST binary data (H)
     --data-urlencode <name=data/name@filename> HTTP POST data url encoded (H)
danielpops
  • 713
  • 6
  • 13