I have a textfile that consists of multiple blocks such as one shown here :
TestVar 00000000 WWWWWW 222.222 222.222 222.222
UNKNOWN ,,,,,,,, ,,,,,, ,,,,,,
I would like to get the folowing output:
Each part is always 8 characters long (e.g TestVar , 00000000)
From each line that start with testvar i would like the code to return:
WWWWWW_00000000
Can someone help me with this I have used regex before but never with python and am quite new to both of them.
Thanks
With regex pattern
^TestVar\s+(\d{8})\s+(\S+)you can get that as >>Test this demo here.
To find all occurrences in multiline
inputstring use:To learn more about regex with Python, see http://docs.python.org/howto/regex.html