Home > Back-end >  how do I parse a varible do isolate a singular piece of data in python?
how do I parse a varible do isolate a singular piece of data in python?

Time:05-17

when I output the variable p using p[0] it outputs

<Ether  dst=4a:aa:ac:d6:57:00 src=99:c3:88:b0:56:2e type=IPv4 |<IP  version=4 ihl=5 tos=0x0 len=32 id=1 flags= frag=0 ttl=64 proto=icmp chksum=0x83e5 src=192.168.50.73 dst=1.2.3.4 |<ICMP  type=echo-request code=0 chksum=0x1026 id=0x0 seq=0x0 unused='' |<Raw  load='test' |>>>>

and I want to isolate the test in <Raw load='test' but that wont always be the same string.

CodePudding user response:

You can use regular expressions:

import re
pattern = r"<Raw\s load='([^'] )'" # \s  is "any # of spaces"
                                   # ([^'] ) is "anything other than a '"
re.findall(pattern, s)
#['test']

CodePudding user response:

thank you for asking this question, its not possible to do what your asking, you should use something like bash instead to parse it. there is no python library that can do what you want that i can think of.

  • Related