lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I tried to send the attached mail through to the list yesterday but it
seemed to get eaten by the ether.

Sorry if this ends up a duplicate post.

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
Many changes of mind and mood; do not hesitate too long.
--- Begin Message ---

Hi,

I'm using Lua 5 to do some work and I can't get a pattern to do what I
want.

For those perlites among us, the regexp I'm trying to replicate is:
  ^\-?\d+(?:\.\d\d)?$

I.E. an optional leading minus, then at least one digit.
     then optionally, a decimal point followed by exactly two digits.

I don't care if it captures or not, but I don't need the capture.

My first try, created the pattern:

  ^%-?%d+(%.%d%d)?$

But that refused to match anything. Particularly the ? after the ()s
seemed to confuse matters.

Currently I have a logic workaround of the form

  ^%-?%d+$  and ^%-?%d+%.%d%d$  as a pair of patterns which I test in
  turn.

This is plainly not ideal.

Any ideas?

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
Tonight's the night: Sleep in a eucalyptus tree.

--- End Message ---