Skip to content

Instantly share code, notes, and snippets.

@supernovel
Last active March 27, 2019 06:00
Show Gist options
  • Save supernovel/638379fbfb5cf6a393b2dc23a365c7e4 to your computer and use it in GitHub Desktop.
Save supernovel/638379fbfb5cf6a393b2dc23a365c7e4 to your computer and use it in GitHub Desktop.
주소 구성
export const Road = /^(.+\s*.+(로|로?\s?(\d+번)?길)\s+([\d-]+)).*$/;
export const RegString = {
DS: '([^\\s\\d]+(도|시))',
S: '([^\\s\\d]+(시))',
SG: '([^\\s\\d]+(시|구))',
SGG: '([^\\s\\d]+(시|군|구))',
GG: '([^\\s\\d]+(군|구))',
EMD: '([^\\s\\d]+(읍|면|\\d?동|동?\\d?가))',
LI: '([^\\s\\d]+(리)(\\(.*\\))?)',
LC: '(산?\\d+(-\\d+)?)번?지?',
Sejong: '(세종(특별)?(자치)?(시)?)'
};
/**
* 주소 문자열의 레벨을 찾고 수정 하기 위함
*/
export const Address = { /* [ 정규식, 레벨, 주소 부분, 지번 부분, 나머지 문자열 부분 ] */
1: [
[new RegExp(`^${RegString.Sejong}\\s*(.*)$`), 2, '$1 $1 $5']
],
2: [
[new RegExp(`^${RegString.DS}\\s*${RegString.SG}\\s*${RegString.GG}$`), 1, '$1 $3 $5'],
[new RegExp(`^${RegString.Sejong}\\s*${RegString.EMD}\\s*${RegString.LI}$`), 3, '$1 $1 $5 $7'],
[new RegExp(`^${RegString.Sejong}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $5 $7', '$7', '$9'],
[new RegExp(`^${RegString.S}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5', '$5', '$7']
],
3: [
[new RegExp(`^${RegString.DS}\\s*${RegString.SG}\\s*${RegString.GG}\\s*${RegString.EMD}$`), 2, '$1 $3@$5 $7'],
[new RegExp(`^${RegString.Sejong}\\s*${RegString.Sejong}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $9 $11', '$11', '$13'],
[new RegExp(`^${RegString.DS}\\s*${RegString.SGG}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $7', '$7', '$9'],
[new RegExp(`^${RegString.S}\\s*${RegString.EMD}\\s*${RegString.LI}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $8', '$8', '$10'],
[new RegExp(`^${RegString.S}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5', '$5', '$7'],
[new RegExp(`^(([^\\s\\d]+[^\\s]*\\s){1,5})${RegString.LC}(.*)$`), 4, '$1 $3', '$3', '$5']
],
4: [
[new RegExp(`^${RegString.DS}\\s*${RegString.SG}\\s*${RegString.GG}\\s*${RegString.EMD}\\s*${RegString.LI}$`), 3, '$1 $3@$5 $7 $9'],
[new RegExp(`^${RegString.Sejong}\\s*${RegString.Sejong}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $9 $11', '$11', '$13'],
[new RegExp(`^${RegString.DS}\\s*${RegString.SG}\\s*${RegString.GG}\\s*${RegString.EMD}\\s*${RegString.LI}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $7 $9 $12', '$12', '$14'],
[new RegExp(`^${RegString.DS}\\s*${RegString.SG}\\s*${RegString.GG}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $7 $9', '$9', '$11'],
[new RegExp(`^${RegString.DS}\\s*${RegString.SGG}\\s*${RegString.EMD}\\s*${RegString.LI}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $7 $10', '$10', '$12'],
[new RegExp(`^${RegString.DS}\\s*${RegString.SGG}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $7', '$7', '$9'],
[new RegExp(`^${RegString.S}\\s*${RegString.EMD}\\s*${RegString.LI}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5 $8', '$8', '$10'],
[new RegExp(`^${RegString.S}\\s*${RegString.EMD}\\s*${RegString.LC}(.*)$`), 4, '$1 $3 $5', '$5', '$7'],
[new RegExp(`^(([^\\s\\d]+[^\\s]*\\s){1,5})${RegString.LC}(.*)$`), 4, '$1 $3', '$3', '$5']
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment