街道地址的正则表达式 [英] Regular expression for street address

查看:71
本文介绍了街道地址的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试匹配包含街道和号码的街道地址.

I am trying to match street addresses containing the street and number.

我需要表达式来匹配街道名称的单词,然后是数字.

I need the expression to match words for the street name, followed by the number.

例如,我想匹配somestreet 25"、some other street 23"、a-third street 190",而不是a_fourth street 67".

For example I want to match "somestreet 25", "some other street 23","a-third street 190", but not "a_fourth street 67".

我尝试了一个小时,但我什至不擅长使用正则表达式.

I am trying with it for an hour but I am not even close to good with regex's.

到目前为止,我得到的只有 /^[a-zA-Z]+([\s][a-zA-Z]+)([\s][0-9]){1,4}$/ 但不用说,它不起作用.

So far all I've got is /^[a-zA-Z]+([\s][a-zA-Z]+)([\s][0-9]){1,4}$/ but needless to say, it is not working.

--- 编辑---

我知道没有标准的全局方式来写街道地址,而且正则表达式不能真正复杂到足以覆盖全局范围内的问题,但该站点是为当地餐馆而设的,并且所有我希望地址看起来像是一个地址(即使那样,如果没有地图和电话验证,它仍然可能是假的).

I understand that there is no standard, global way of writing the street address, and that regular expressions can't really be complicated enough to cover the problem on a global scope, but the site is for a local restaurant, and all I want is the address to look like it could be an address (even then, without map and telephone verification it could still be a fake one).

然而,在发送任何东西之前都会有人工验证,而且它是一个相当小的社区,所以送货人和餐厅老板都知道订单是否是假的.

There will, however, be human verification at all times before anything is sent, and also it is a rather small neighborhood, so both the delivery person and the restaurant owner know if the order is fake or not.

我想要的只是防止他们在地址中收到愚蠢的 !@#$ 字符的垃圾邮件,并有一个体面的可读地址格式供他们使用.

All I want is to keep them from getting spammed with silly !@#$ characters in the address, and have a decent readable address formatting for them to work with.

推荐答案

这应该适用于您的示例:

This should work on your examples:

/^[a-zA-Z]([a-zA-Z-]+\s)+\d{1,4}$/

这篇关于街道地址的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆