如何为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
答案 0 :(得分:1)
至少删除regexp_contains
中地址周围的引号select address, regexp_contains(address, r"\s\d{5}$") check from table1
此外,您可能希望在正则表达式结束时重新使用$
将r"\b\d{5}\b"
视为选项