String-before() and string-after() function support

Hi @Zuhaib_Shaik,

@Snehaniranjana has given the right approach, but unfortunately there is no function that I'm aware of which can "find location of" the '-' character. (Available functions are listed here)

It is however possible to use if() and regex() to get the desired functionality, as long as there is an upper limit to the number of digits before the '-' character, e.g. ID num will never be longer than 8 digits.

if( regex(${ID},'^\d-'), substr(${ID},0,1),
    if( regex(${ID},'^\d{2}-'), substr(str,0,2),
        if( regex(${ID},'^\d{3}-'), substr(str,0,3),
            if( regex(${ID},'^\d{4}-'), substr(str,0,4),
                'ID could not be extracted'))))

Explanation:
If ID string is a digit followed by '-', return just first character,
else if ID string is 2 digits followed by '-', return first 2 characters,
else if ID string is 3 digits followed by '-', return first 3 characters,
else if ID string is 4 digits followed by '-', return first 4 characters,
else return 'ID could not be extracted'

If your ID is not just digits (0..9), but letters as well (a-z, A-Z) you can use \w instead of \d

If your ID can be more than 4 digits, extend the code above to cater for more digits.

Note: I've tested the regex, but not the rest of the code above

Regards,
Andrew

1 Like