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

How to get the last characters after the third "_" in Jinja

Need help to get the string after the third "_"

Example

r_a_B_TEXAS
r_asda_Bads_DALLAS
r_asda_Bads_DISNEY_LAND
rdd_asda_Bads_Florida_MIAMI_NICE

I need this output:

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

TEXAS
DALLAS
DISNEY_LAND
Florida_MIAMI_NICE

With split function:

hostname.split('_')[3]

I only get the third value but for DISNEY_LAND I only get DISNEY and wanna have everything DISNEY_LAND

>Solution :

You should be able to specify the max splits that you want to perform to accomplish this:

>>> string = "r_asda_Bads_DISNEY_LAND"
>>> string.split("_", 3)[3]
'DISNEY_LAND'

See https://docs.python.org/3/library/stdtypes.html#str.split

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