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

remove gibberish prefix from a string

a = "aajfkdfvf_valid_name0" 
b = "gdhdhsdsdeeeeex_valid_name1"

How do I remove the gibberish from my string before valid so that I have something like this –

valid_name0
valid_name1

>Solution :

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

If your strings always contains valid word, then you can try something like –

a = "aajfkdfvf_valid_name0" 
b = "gdhdhsdsdeeeeex_valid_name1"
for s in (a, b):
    print(s[s.rfind('valid'):])

So, even if the prefix contains _ or substring valid in it, the output will be correct. Though if your valid substring contains the word valid multiple times, then this will not work

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