最终解决方案
/(\d{1,5}\s[^\d].{5,20}(dr|drive)(\.|\s|\,))/i
原始问题
正则表达式
/([0-9]{1,5}.{5,20}(dr|drive)(\.|\s|\,))/i
图案
PO Box 66 23 Britton Drive Bloomfield CT 06002
此正则表达式返回“ 66 23 Britton Drive”。我想退回'23 Britton Drive'。我已经尝试了Regex的以下变体:
/(([0-9]{1,5}.{5,20})?(dr|drive)(\.|\s|\,))/i - adding a new capturing group and making it uncreedy
/([0-9]{1,5}.{5,20}?(dr|drive)(\.|\s|\,))/i - making the length of in between characters ungreedy
/([0-9]{1,5}.{5,20}(dr|drive)(\.|\s|\,))/Ui - adding ungreedy modifier
更多无效的模式
PO Box 156 430 S Wheeling Dr. Wheeling, IL 60090
有效的模式
1195 Columbia Dr PO Box 1256 Longview, WA 98632
3400 SW Washington drive PO Box 1349 Peoria, IL 61654
^[^\d]+\d{2} (\d{2} [^ ]+ [^ ]+)
显然,我需要更多的模式才能在所有情况下都可以使用
当前RegEx的小补丁
(\d{1,5} [^\d]{5,20}(dr|drive)(\.|\s|\,))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句