Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use regular expressions to extract provinces, cities and counties from addresses in JavaScript

Shulou Source: shulou.com Published: 2022-06-02 11:17:13 10月03日 Update

How to use regular expressions to extract provinces, cities and counties from addresses in JavaScript? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

General domestic address return Array the first three items are provinces, cities and counties, if you want to expand to the community, streets, etc., you can expand yourself.

Var add1 ='34 Tianma Town, Dujiangyan City, Chengdu City, Sichuan Province'; var add2 = 'No. 1 Qianmen Street, Dongcheng District, Beijing' var add3 = 'Zhongshan Road, Tianshan District, Urumqi City, Xinjiang Uygur Autonomous region'; var add4 = 'Happiness Community, Shuangliu County, Chengdu City, Sichuan Province'; var add5 = 'Jianshazui Road, Central and Western District, Hong Kong Special Administrative region'; var reg = /. +? (province | city | autonomous region | autonomous prefecture | county | district) / g; console.log (add1 +':', add1.match (reg)); console.log (add2 +':', add2.match (reg)); console.log (add3 +':', add3.match (reg)); console.log (add4 +':', add4.match (reg)); console.log (add5 +':', add5.match (reg))

Return the result

This is the answer to the question about how to use regular expressions to extract provinces, cities and counties from the address in JavaScript. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Address province and city problem regular expression more community Beijing Sichuan Sichuan Chengdu Chengdu autonomous region help autonomy solution easy easy street Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Apple OPPO Reno MySQL Huawei