[hashcash] Re: new format tweak coming...

>>>>> "Justin" == Justin Mason <jm@xxxxxxxxxx> writes:

Justin> Oh good, you'd be happy to provide a regex that'll do the above
Justin> left-to-right scan to cope with

Justin>   foo:"bar \\\\\\\\\\\\\\\":baz":blargh

Justin> then.  as far as I know it can be done with perl re's, but I
Justin> don't know the recipe off-hand ;)

What do you want the regexp to do?  Just match the value part of the
string?  `"([^\"]|\\.)*"' should do the trick.  (Or something like that,
depending on what needs to be escaped, etc.)  No Perl extensions
needed.  Just straight regexp.

Breaking it down:
Start with the first quote: "
(
  match anything other than a backslash or quote: [^\"]
  (I think that a backslash within [ ] doesn't usually need to be
  escaped, but I'm not sure.)
    or |
  match a backslash, followed by any other character: \\.
  (assuming backslash needs to be escaped here)
)
any number of times: *
And finally the end quote: "

This is making the simplifying assumption that a backslash followed by
a character means that the following character is meant to be a
literal.  If not, it's easy to change the backslash matching part (to
something like `\\[\"]').

Not tested.  Just off the top of my head.

-- 
Hubert Chan <hubert@xxxxxxxxx> - http://www.uhoreg.ca/
PGP/GnuPG key: 1024D/124B61FA
Fingerprint: 96C5 012F 5F74 A5F7 1FF7  5291 AF29 C719 124B 61FA
Key available at wwwkeys.pgp.net.   Encrypted e-mail preferred.


Other related posts: