KAPOW

Would you like to react to this message? Create an account in a few clicks or log in to continue.
KAPOW

Welcome to the Kapow forum. Here you can get help, use your skills to help others and enjoy hanging out in the company of other Kapow Robot Developers.


2 posters

    How Extract Last 4 characters of a string

    avatar
    tfkpw17


    Posts : 6
    Points : 2645
    Join date : 2017-08-31

    How Extract Last 4 characters of a string Empty How Extract Last 4 characters of a string

    Post by tfkpw17 Fri Sep 08, 2017 10:25 pm

    Hi All,

    I am looking to extract the last four characters of a short text variable and test these against the last four characters of another.

    For Example:
    Variable 1 - 1928387-1983
    Variable 2 - 22228881768

    I would want to extract 1983 from variable 1 and 1768 from variable 2 and test these values against each other to see if they match.

    Any help would be much appreciated.
    jking
    jking


    Posts : 103
    Points : 4053
    Join date : 2014-03-01
    Location : USA

    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by jking Sat Sep 09, 2017 3:12 am

    In your extract step, add a Converter Text Formatting Replace Pattern.

    Your pattern will be to ignore everything except the last 4 characters in the string.  Both examples below will give the same results:

    Pattern     .*(.{4})   Read as ignore everything except the last 4 repitions of any character.
    Pattern     .*(....)     Read as ignore everything except the last 4 characters.

    Note that you may need to trim spaces prior to your replace pattern step.

    After you have extracted and applied the Replace Pattern Converter  you can use a Test Variables step.
    avatar
    tfkpw17


    Posts : 6
    Points : 2645
    Join date : 2017-08-31

    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by tfkpw17 Wed Sep 13, 2017 7:00 pm

    Thanks JKing, Much appreciated.
    avatar
    tfkpw17


    Posts : 6
    Points : 2645
    Join date : 2017-08-31

    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by tfkpw17 Wed Sep 13, 2017 7:07 pm

    Hi JKing,

    I have a similar issue regarding data extraction where I need to extract two words from one string into two separate variables.

    I am looking to extract the first word up until the first space into once variable and the last word starting from the last space into another.

    Example1:

    Variable 1: FirstName LastName
    I would want to extract Firstname into a variable and LastName into another variable.


    Example2:

    Variable1: FirstName MiddleName LastName
    I would want to extract Firstname into a variable and LastName into another variable ignoring MiddleName.

    Thanks for your help
    jking
    jking


    Posts : 103
    Points : 4053
    Join date : 2014-03-01
    Location : USA

    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by jking Wed Sep 13, 2017 7:42 pm

    Names are a bit trickier to pattern out in that names do not always match a standard pattern.
    A first name may be one character string or multiple character strings.  For instance, a first name could be Jim or Jon or Tom or Nancy, Ann, Beth, etc.
    A first name could be Mary Elizabeth, Billy Bob, John Michael, BJ, KC, etc.
    In a similar fashion, last names can be one continuous string, hyphenated, separated by a space or contain post-nominal initials (III, IV, JR, SR, MD, PhD, etc.).

    Using Jim King as the name example:
    The simplest pattern to extract everything up to the 1st space and ignore everything else is:  (.*)\s.*    results is Jim
    The simplest pattern to extract the last name is .*\s   result is King

    However, if the name is more complex, for example ROBERT B PARRAMORE-SMITH IV, then 
    (.*)\s.*  results is ROBERT B PARRAMORE
    .*\s       result is IV
    Those would not be the results you would want.

    A more complex pattern would return the correct last name:
    ^([A-z][A-Za-z]*\s+[A-Za-z]*)|([A-z][A-Za-z]*)$
    Replace Expression:1   ROBERT B PARRAMORE-SMITH 
    Replace Expression:2   PARRAMORE-SMITH IV
    Replace Expression:3   PARRAMORE-SMITH
    nb: the Replace Expression: 3 is key to this pattern working correctly!


    A google search on Regular Expressions should result in several resources what include patterns for First Name and Last Name.  

    Good luck with this.  Since names are inherently unstructured this is more difficult to do with your robot.


    EDIT:

    The is also the issue of pre-nominal titles: Dr, Fr, Sr, Mr, Mrs, Ms, etc., etc., etc.  These add additional levels of complexity.
    avatar
    tfkpw17


    Posts : 6
    Points : 2645
    Join date : 2017-08-31

    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by tfkpw17 Mon Oct 30, 2017 9:20 pm

    Thanks for all your help with this issue.

    Regards

    Sponsored content


    How Extract Last 4 characters of a string Empty Re: How Extract Last 4 characters of a string

    Post by Sponsored content


      Current date/time is Fri Nov 15, 2024 2:15 pm