14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptの正規表現

Last updated at Posted at 2012-03-16

string.replace(/[ア-ン]/g, "")では, JavaScriptは全ての半角カナを取り除くことはできない. 実際に, "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンァィゥェォャュョッー".replace(/[ア-ン]/g, "")="ヲァィゥェォャュョッー"となってしまう.

では全ての半角カナを取り除くにはどうするか?

string.replace(/[ヲ-ン]/g, "")としてやればいい. 奇妙なようにも見えるのだが.

14
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?