regex blindness

J

Josselin

I was blind yesterday .. could not find what's wrong in this regex (and
posted that to mac os forum)

/^(?k: ( ?k:0[1-9]|[1-8][0-9]|9[0-8] ) (?k: [0-9]{3} ) )$/

trying to check zipcodes (french cities : like 78231)

got an undefined (?...) sequence:
/^(?k:(?k:0[1-9]|[1-8][0-9]|9[0-8])(?k:[0-9]{3}))$/

I am also checking email addresses with :
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\.\-])+\.)+([a-zA-Z0-9]{2,4})+$/

is there a better regexp for that ...

thanks
joss
 
R

Robert Klemme

Josselin said:
I was blind yesterday .. could not find what's wrong in this regex (and
posted that to mac os forum)

/^(?k: ( ?k:0[1-9]|[1-8][0-9]|9[0-8] ) (?k: [0-9]{3} ) )$/

trying to check zipcodes (french cities : like 78231)

got an undefined (?...) sequence:
/^(?k:(?k:0[1-9]|[1-8][0-9]|9[0-8])(?k:[0-9]{3}))$/

irb(main):001:0> /(?:x)/
=> /(?:x)/
irb(main):002:0> /(?k:x)/
SyntaxError: compile error
(irb):2: undefined (?...) sequence: /(?k:x)/
from (irb):2
from :0
irb(main):003:0> /(?i:x)/
=> /(?i:x)/

Ruby does not allow the "k" flag there. And I believe Ruby does not
have that RX flag at all.
I am also checking email addresses with :
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\.\-])+\.)+([a-zA-Z0-9]{2,4})+$/

is there a better regexp for that ...

I guess you'll find out plenty out there. The answer to "better"
heavily depends on what your goals are (simpler RX, faster matching),
what RX engine you are using and what data you are processing. Example:
in some cases /[^@\s]+@[^@\s]+/ might be perfectly ok to match an email
address - in other cases it won't.

Kind regards

robert
 
J

Josselin

Josselin said:
I was blind yesterday .. could not find what's wrong in this regex (and
posted that to mac os forum)

/^(?k: ( ?k:0[1-9]|[1-8][0-9]|9[0-8] ) (?k: [0-9]{3} ) )$/

trying to check zipcodes (french cities : like 78231)

got an undefined (?...) sequence:
/^(?k:(?k:0[1-9]|[1-8][0-9]|9[0-8])(?k:[0-9]{3}))$/

irb(main):001:0> /(?:x)/
=> /(?:x)/
irb(main):002:0> /(?k:x)/
SyntaxError: compile error
(irb):2: undefined (?...) sequence: /(?k:x)/
from (irb):2
from :0
irb(main):003:0> /(?i:x)/
=> /(?i:x)/

Ruby does not allow the "k" flag there. And I believe Ruby does not
have that RX flag at all.
I am also checking email addresses with :
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\.\-])+\.)+([a-zA-Z0-9]{2,4})+$/

is there a better regexp for that ...

I guess you'll find out plenty out there. The answer to "better"
heavily depends on what your goals are (simpler RX, faster matching),
what RX engine you are using and what data you are processing.
Example: in some cases /[^@\s]+@[^@\s]+/ might be perfectly ok to match
an email address - in other cases it won't.

Kind regards

robert

thanks for your advice, removing the k flag was the k-point..
joss
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top