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

Filter based on keyword python

I am trying to get only the host information from the below sample data. but somehow i struck. can you pls help

DATA="Attempting to contact (DESCRIPTION = (SDU=32767)(SEND_BUF_SIZE=16777216)(RECV_BUF_SIZE=16777216) (ADDRESS = (PROTOCOL = TCPS)(HOST =host1-1-ia2-vip.world.net)(PORT = 1523)) (ADDRESS = (PROTOCOL = TCPS)(HOST = host2-2-ia2-vip.world.net)(PORT = 1523)) (LOAD_BALANCE = YES) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = TESTDB92)))"

m = re.search('HOST\s\w+\s(\w+)',data) ==> this is not filtering
m.group(1)

Desired output :

host1-1-ia2-vip.world.net
host1-2-ia2-vip.world.net

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

>Solution :

import re

DATA = "Attempting to contact (DESCRIPTION = (SDU=32767)(SEND_BUF_SIZE=16777216)(RECV_BUF_SIZE=16777216) (ADDRESS = (PROTOCOL = TCPS)(HOST =host1-1-ia2-vip.world.net)(PORT = 1523)) (ADDRESS = (PROTOCOL = TCPS)(HOST = host2-2-ia2-vip.world.net)(PORT = 1523)) (LOAD_BALANCE = YES) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = TESTDB92)))"

hostnames = re.findall(r'HOST\s*=\s*([\w\.-]+)', DATA)
result = '\n'.join(hostnames)

print(result)

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