[Expo-tech] cracked regex
Wookey
wookey at wookware.org
Wed May 13 20:07:31 BST 2020
On 2020-05-13 19:38 +0100, Philip Sargent (Gmail) wrote:
> Hah. In your face regex:
> regex_starref =
> re.compile(r'^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(
> .*?\d+.*?)$(?i)')
Putting in a ?x and some comments would be helpful (assuming that re.compile supports that)
'?x
^\s*\*ref # look for *ref at start of line
[\s.:]* # some spaces or colons
((?:19[6789]\d)|(?:20[0123]\d)) # a date from 1960 to 2039
\s*# # hash separator (need to escape the actual hash I guess?)
?\s*(X) # optional X
?\s*(.*?\d+.*?) # maybe a space, then at least one digit in the string
$(?i)' # the end (do the whole thing case insensitively)
So much easier if you ever have to edit the damn thing.
(.*?\d+.*?) seems like it might be a bit lax? Comments afterwards is fair
enough, but 'as much text as you like' between the # and wallet ID?
> I have beaten the monster.
Satisfying when it works, isn't it?
Wookey
--
Principal hats: Linaro, Debian, Wookware, ARM
http://wookware.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.wookware.org/pipermail/expo-tech/attachments/20200513/d588bc89/attachment.sig>
More information about the Expo-tech
mailing list