How do you find Korean letters using regex in JavaScript?
Asked
Active
Viewed 1.1k times
3
-
Closing this as duplicate of a newer question which solves problems in the answer to this one. – deceze Oct 25 '18 at 22:03
1 Answers
6
You can use the following regex
const re = /[\u3131-\uD79D]/ugi
This is the code table that I referenced: http://memory.loc.gov/diglib/codetables/9.3.html
Try it yourself:
const re = /[\u3131-\uD79D]/ugi
console.log("abcde".match(re)) // null
console.log("안녕".match(re)) // ["안", "녕"]

Maximus S
- 10,759
- 19
- 75
- 154
-
5What about `var hangul =/[\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uAC00-\uD7AF\uD7B0-\uD7FF]/g`? It does not even require the `/u` modifier. Also, here is a similar solution to yours without a regex: https://github.com/stonexx/hangul.js/blob/master/src/isHangul.js – Wiktor Stribiżew Jul 02 '16 at 09:18
-
4One shouldn't rely on this regexp. For instance `'餃'.match(re) !== null` will returns `true` which doesn't comply with the problem "is the input ONLY a Korean string" ? – vdegenne Oct 25 '18 at 12:12
-
3https://stackoverflow.com/questions/52989330/what-is-proper-way-to-test-if-the-input-is-korean-or-chinese-using-javascript – vdegenne Oct 25 '18 at 12:46