Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regex: return name of street without street type or number

    I have a variable of addresses and I would like to capture just the name of the street with a regular expression. This is without the street type, address number, or cardinal direction. There are some errors in formatting but all characters are in capital letters. So,

    Code:
    2038 W MAIN AVE
    2038QWEW S JEFFERSON AVENUE
    33 NORTH CALIFORNIA STREET
    53371 WASHINGTON AVENUE
    1600 E PENNSYLVANIA AVE
    WEST9 67ST ST
    E171 23RD STREET
    G171 N121ST STREET
    13 NM ROUTE 66
    ought to return

    Code:
    MAIN
    JEFFERSON
    CALIFORNIA
    WASHINGTON
    PENNSYLVANIA
    67ST
    23RD
    121ST
    NM
    So far I've got

    Code:
    gen street_name = regexs(0) if(regexm(address, "\b(?:(?:WEST|NORTH|EAST|SOUTH)\d*|(?!^)[NEWS](?![a-z])) *(\S+)")
    But every time that I try to run it, I get an error saying

    Code:
    regexp: ?+* follows nothing
    and it sets all values to missing.

  • #2
    I was able to figure this out

    Code:
    g addr_else = regexs(0) if(regexm(address, "[0-9A-Z]* [0-9A-Z]*$"))
    split addr_else , g(addr_name) p(" ")
    rename addr_name1 street_name
    rename addr_name2 street_type
    This works in all cases with the exception of the last one with the funky street type

    Comment

    Working...
    X