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
>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)