sivabudh sivabudh - 2 years ago 217
Ruby Question

Doesn't Ruby have isalpha?

Like Python? I'm trying to check whether each character in a string is an alphanumeric or not?

Answer Source

There's a special character class for this:

char.match(/^[[:alpha:]]$/)

That should match a single alphabetic character. It also seems to work for UTF-8.

To test a whole string:

string.match(/^[[:alpha:]]+$/)

Keep in mind this doesn't account for spaces or punctuation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download