Is [:alnum:] equivalent to [A-Za-z0-9]?

J

Jeff

Hi,

I'm trying to creating a regex that will match a string that starts and
ends with an alphanumeric character, and has alphanumeric characters or
dashes in the middle.

This regex gives the expected result:
irb(main):008:0> /^[:alnum:][A-Za-z0-9\-]*[A-Za-z0-9]$/ =~ "apple!"
=> nil
irb(main):009:0> /^[:alnum:][A-Za-z0-9\-]*[A-Za-z0-9]$/ =~ "apple"
=> 0

This regex works as expected on "apple!", but returns nil on "apple":
irb(main):010:0> /^[:alnum:][A-Za-z0-9\-]*[:alnum:]$/ =~ "apple!"
=> nil
irb(main):011:0> /^[:alnum:][A-Za-z0-9\-]*[:alnum:]$/ =~ "apple"
=> nil

Can anyone explain this?

Thanks,
Jeff
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top