邮政编码模式的正则表达式?

时间:2018-03-26 19:58:22

标签: google-bigquery

如何为zipcode模式编写正则表达式?我需要确保所有的zipcodes(示例地址)都是5位数,但我的查询不起作用。

with table1 as(
select "123 6th St. Melbourne, FL 32904" as address union all
select "71 Pilgrim Avenue, Chevy Chase, MD 20815"  union all
select "70 Bowman St. South Windsor, CT 06074" union all
select "4 Goldfield Rd. Honolulu, HI 966815"  union all
select "44 Shirley Ave. West Chicago, IL 60185" union all
select "514 S. Magnolia St. Orlando, FL 32806 "
)
select address,regexp_contains("address",r"\s\d{5}$")check from table1

1 个答案:

答案 0 :(得分:1)

至少删除regexp_contains

中地址周围的引号
select address, regexp_contains(address, r"\s\d{5}$") check from table1  

此外,您可能希望在正则表达式结束时重新使用$

r"\b\d{5}\b"视为选项