Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从地址中过滤出小区名称 #106

Open
lizhongzhen11 opened this issue Mar 23, 2021 · 0 comments
Open

从地址中过滤出小区名称 #106

lizhongzhen11 opened this issue Mar 23, 2021 · 0 comments

Comments

@lizhongzhen11
Copy link
Owner

lizhongzhen11 commented Mar 23, 2021

const getCommunity = (address) => {
  const filterArea = (str) => {
    const temp = str.match(/(?<=(路\d+号)|(路\d+#)|(街\d+号)|(街道\d+号)|侧|组|镇|广陵区|邗江区|江都区|江都市|仪征市|高邮市|宝应县|扬州市).+/);
    return temp ? filterArea(temp[0]) : ['侧', '组', '路', '村', '道', '镇'].includes(str.slice(-1)) ? '' : str;
  }

  const filterSpecial = (str) => {
    const temp = str.match(/(?<=路|街道).+/);
    return temp ? filterSpecial(temp[0]) : str;
  }

  const filterNumber = (str) => {
    const temp = str.match(/(?=\d+)/);
    return temp ? str.substring(0, temp.index) : str;
  }

  const community = filterNumber(filterSpecial(filterArea(address || '')));
  return community.length > 2 ? community : '';
}

大概能用,毕竟用户地址都是手填,按照一定规则的能过滤出来,不符合规则的就算了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant