benburkert / randexp

generate random data from a Regular Expression
MIT License
286 stars 43 forks source link

It don't know about character class #15

Open deemytch opened 10 years ago

deemytch commented 10 years ago

/^[0-9a-f]{24}$/.gen produces "^[0-9a-f]]]]]]]]]]]]]]]]]]]]]]]]$"

must be a long hex number

bbrotherton commented 10 years ago

I believe you may have meant:

/^[0-9a-f]{,24}$/.gen

However, I am not sure what omitting the comma SHOULD do.

deemytch commented 10 years ago

No, I mean exactly that. In regexpes: {number} means exactly that number of repetitions {,number} means "no more" {number,} means "more than" {number,number} means "between"

that's expression /[0-9a-fA-F]{32}/ correspond to the output of SecureRandom.hex(32)

example:

$ irb
> "bbaaaaa" =~ /a{5}/
=> 2
irb(main):002:0> "aaaaa" =~ /a{6}/
=> nil
bbrotherton commented 10 years ago

Sorry. You're right. It's been a while since I've worked with regexes extensively. Even then I probably would have used {24,24}.

It is a bit odd that there are 24 closing square brackets (']'). Almost like it too all the preceding characters as literals...