Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I match Korean characters in a Ruby regular expression?

I have some basic validations for usernames using regular expressions, something like [\w-_]+, and I want to add support for Korean alphabet, while still keeping the validation the same.

I don't want to allow special characters, such as {}[]!@#$%^&*() etc., I just want to replace the \w with something that matches a given alphabet in addition to [a-zA-Z0-9].

Which means username like 안녕 should be valid, but not 안녕[].

I need to do this in Ruby 1.9.

like image 406
Jakub Arnold Avatar asked Apr 13 '12 11:04

Jakub Arnold


1 Answers

try this:

[가-힣]+

This matches every character from U+AC00 to U+D7A3, which is probably enough for your interest. (I don't think you'll need old hangul characters and stuff)

like image 121
김민준 Avatar answered Oct 12 '22 11:10

김민준