douwen3083 2012-03-05 19:24
浏览 315
已采纳

街道地址的正则表达式

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.

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.

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.

--- EDIT ---

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.

  • 写回答

3条回答 默认 最新

  • douqiao5314 2012-03-05 19:31
    关注

    This should work on your examples:

    /^[a-zA-Z]([a-zA-Z-]+\s)+\d{1,4}$/
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭