Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing extra spaces from string when it contains a \ character

I am getting a string in this form:

my_string = "select \\\"ASSETS\\\" AS \\\"LEASE_ASSETS\\\", count(*) CNT FROM \\\"SIY\\\".\\\"I7_MAIN_ACCOUNT\\\" group by \\\"ASSETS\\\" order by \\\"ASSETS\\\""

I want to remove these \\\, but I am not sure if str.replace() is a good option.

The main thing I want is to get this Table name part from it, like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"SIY.I7_MAIN_ACCOUNT"

… which, due to those spaces, I am not able to get. I want to do it by using str.replace(), but it seems both are not working.

>Solution :

If query will be the same then you filter un wanted things one by one then extract your required words

import re

my_string = "select \\\"ASSETS\\\" AS \\\"LEASE_ASSETS\\\", count(*) CNT FROM \\\"SIY\\\".\\\"I7_MAIN_ACCOUNT\\\" group by \\\"ASSETS\\\" order by \\\"ASSETS\\\""
my_string= my_string.replace("\\", '').replace('"', '')
print (my_string[my_string.find('FROM ')+len('FROM '):my_string.rfind('group')])

Gives #

SIY.I7_MAIN_ACCOUNT 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading