'How to prevent python from automatically escaping backslash with dubble backslash
I'm looking for a method to forward a string
so for example ip 1.1.1.1
becomes ^1\.1\.1\.1$
.
I tried a couple of thing but all of them results in the following ^1\\.1\\.1\\.1$
, but unfortunately influxdb (1.8) can't handle that.
I'm trying to query to Influx via their official python api. But they literally forward the query inserted into there client class. query as string when printed in the console
SELECT "value" FROM "7d_5m"."ping_packets_loss" WHERE "ip" =~ /(^1\.0\.0\.0)/
query preceived in the influx logging with either of the methods
SELECT value FROM prometheus.\"7d_5m\".ping_packets_loss WHERE ip =~ /(^203\\.221\\.167\\.19$)/
I already tried re.sub(), str.replace(), split/join and re.escape(). All of them with either \ and char(92)
Any more suggestions?
[Edit]
I tried the re.escape() method again. And this time it worked. I don't know why, and what I dit wrong before. But it works better than executing an remote bash script :) re.sub(), str.replace() and split/join still do not work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|