problems with a regular expression
I'm trying to get a correct regular expressi开发者_如何学Pythonon for this problem:
I get a result from a webservice as a string that looks like this
tag: 54e16e66 (Mifare card standard)
I need to extract the 54e16e66 part (which is in hexa) only, regardless of what is before and after that part, i've tried several patterns, but I am not confident enough with regex and I can't seem to find a pattern that works.
Edit
"tag :" is aways present.
the hexa part I want to extract has variable length
what is after is a user comment, so it could be anything
Could someone help ? thanks in advance ! Michael
Assuming your string there is a good template, and assuming a posix regular expression parser,
/^tag: ([0-9a-f]{8})/
should work. If the length is variable, you would just change the {8}
to {m,n}
, where m
and n
are the minimum and maximum possible number of characters you can expect, respectively.
精彩评论