19
9

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.

都道府県と市町村区を分割し、配列に格納する。

Last updated at Posted at 2015-02-28

都道府県名の大体は3文字目を"都道府県"のいずれかにマッチさせることで対応できます。
神奈川県、和歌山県、鹿児島県の3県だけ4文字目でも"県"をマッチできるようにします。

replace()で空白を入れて、split()で分割します。

'東京都文京区本郷'
.replace(/^(.{2}[都道府県]|.{3})(.+)/, "$1 $2")
.split(' ')

// ['東京都','文京区本郷']  
19
9
0

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
19
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?