LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  extracting a postcode from inside a string

    Employee
    Posted 11-11-2014 08:49

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dhrobertson

    Hi all,

    I have a string field that has had the postcode embedded in it. I need to extract the postcode in order to make it into a new field. most of the fields have the same pattern, however, 1 field doesn't follow that format (CO. Londonderry). I have copied what I have done to get around the issue, but I'm wondering whether there is a neater way and more predictable way for doing this? it is fine if every time the postcode is at the end, but possible they decide to do something silly and it is not at the end which would mean my scripts wouldn't work. It would be great if there was some sort of pattern function that could find the pattern of a postcode and extract that, but I don't think there is anything like that for the fields themselves. I know there is something for the column names but I don't think there is anything for the fields...

    anyway. here is what I have. if anyone has a better solution, please let me know?

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=54622dfc3f1d7e9c
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Account Name:string
    APPLE PARK LH9 7HT
    PEAR CITY LT95 6RT
    NTH WEST CO. LONDONDERRY
    ORANGE TOWN GT5 4RD

    EOX
    editor:XY=160,50
    end:Static_Data

    node:Filter
    bretype:core::Filter
    editor:sortkey=54622e222a756481
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX

    temp_postcode = 'Account Name'.right(15)
    postcode = ltrim(if toUpper(temp_postcode) == "CO. LONDONDERRY" then temp_postcode else temp_postcode.right(8))

    emit 'Account Name',postcode
    EOX
    editor:XY=300,50
    end:Filter


  • 2.  RE: extracting a postcode from inside a string

    Employee
    Posted 11-12-2014 01:43

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: andycooper

    Hi Doug,

    Using the following you can identify where there is a valid post code sequence: -

    emit *
    where 'Account Name'.regexIsMatch("\\w\\w\\d\\d") or 'Account Name'.regexIsMatch("\\w\\w\\d")

    This example works for all the post codes in your static data sample but would not select a two character post code such as E1 or M1; you could add an additional 'Account Name'.regexIsMatch("\\w\\d") to include this.

    This wouldn't deal with your Co.Londonderry value but it depends on how you want to treat values where their isn't a post code.

    Ta

    Andy