c# - Capturing hex data packets with regular expressions -
i'm trying figure out best way capture data packets present in string contains otherwise unwanted characters. data packets in hex, typically grouped bytes white space in-between. packets vary in length , delimited @ beginning , end "10" , "10 03" respectively. thus, bit of text packet in may this:
gibberish 10 01 23 ab cd ef 10 03 gibberish
i can regex capture string of hex bytes enough, without accounting delimiters multiple hex packets can become one, or unwanted characters @ beginning or end happen hex can lumped in packet. how can regex account delimiters?
can think of ways around without using regular expressions, doesn't seem efficient.
generally, gibberish @ beginning referring memory address. contiguous string, without white-space. hence, use \s+
capture that.
since hex data delimited 10
@ beginning , 10 03
@ end, use them:
^\s+ (10 (?:[0-9a-f]{2} )+10 03)
a demo at regex101.
ps: you'll have use regexoptions.ignorecase
flag.
Comments
Post a Comment