problems with regular expressions and parenthesis

D

Daniel Fac

hi,
i'm having some trouble with regular expressions in ruby.
If I have a regular expression like this:
^([\x20-\x7E]|\w){1,40}$, it will crash ruby if there are more than
forty characters in it. I don't understand what is wrong with this
expression, if my expression is changed to
^([\A-Za-z]|\w){1,40}$ it works perfectly well
so does this one: ^([\x20-\x7E]|\w){1,40}$
am I missing something obvious?
 
W

William James

Daniel said:
hi,
i'm having some trouble with regular expressions in ruby.
If I have a regular expression like this:
^([\x20-\x7E]|\w){1,40}$, it will crash ruby if there are more than
forty characters in it. I don't understand what is wrong with this
expression, if my expression is changed to
^([\A-Za-z]|\w){1,40}$ it works perfectly well
so does this one: ^([\x20-\x7E]|\w){1,40}$

What do you mean by "so does this one"?

It's the same as the first one.
 
D

Daniel Fac

Daniel said:
hi,
i'm having some trouble with regular expressions in ruby.
If I have a regular expression like this:
^([\x20-\x7E]|\w){1,40}$, it will crash ruby if there are more than
forty characters in it. I don't understand what is wrong with this
expression, if my expression is changed to
^([\A-Za-z]|\w){1,40}$ it works perfectly well
so does this one: ^([\x20-\x7E]|\w){1,40}$
am I missing something obvious?

Sorry, copied it wrong:
/^([A-Za-z]|\w|\s){1,40}$/
Could it have something to do with some parts of it overlapping?
 
D

Daniel Fac

Daniel said:
Daniel said:
hi,
i'm having some trouble with regular expressions in ruby.
If I have a regular expression like this:
^([\x20-\x7E]|\w){1,40}$, it will crash ruby if there are more than
forty characters in it. I don't understand what is wrong with this
expression, if my expression is changed to
^([\A-Za-z]|\w){1,40}$ it works perfectly well
so does this one: ^([\x20-\x7E]|\w){1,40}$
am I missing something obvious?

Sorry, copied it wrong:
/^([A-Za-z]|\w|\s){1,40}$/
Could it have something to do with some parts of it overlapping?

Sorry, got it wrong again, these expression do not work:
/^([A-Za-z]|\w|\s){1,40}$/
^([\x20-\x7E]|\w){1,40}$

and these do:
/^([\x20-\x7E]|\s){1,40}$/
/^([A-Za-z]|\w){1,40}$/
/^([A-Za-z]|\w){1,40}$/
sorry about that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top