Regular Expressions
Peter Hansen
peter at engcorp.com
Wed Apr 12 15:30:41 EDT 2006
david brochu jr wrote:
> I am trying to grab the following string out of a text file using
> regular expression (re module):
Why do you have to use a regular expression?
> "DcaVer"=dword:00000640
Is all your other input pretty much identical in form? Specifically,
the number of interest is the last thing on the line, and always
preceded by a colon?
> What I need to do with that string is trim down " "DcaVer"=dword:" and
> convert the remaining number from hex to dec.
What does "trim down" mean? Do you need something out of the string, or
are you just discarding/ignoring it?
> I have been trying to figure this out for a while..I am fairly new so
> please any help would be greatly appreciated.
s = '"DcaVer"=dword:00000640'
value = int(s.split(':')[-1], 16)
(In other words, split on colons, take the last field and, treating it
as a hex value, convert to an integer.)
-Peter
More information about the Python-list
mailing list