Regex blindness

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

Josselin wrote:

is there a better regexp for that …

State the problem, not the solution. Describe the exact requirements to
be
met. Give an example of the data to be tested. Then someone will offer a
working regular expression.

On 2006-10-28 10:11:49 +0200, Robert K. [email protected]
said:

Ruby does not allow the “k” flag there. And I believe Ruby does not
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

Josselin wrote:

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

Josselin [email protected] writes:

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 …

Yes, try /@/.