COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Cogency on 20 May 2025 10:59:50 PM

Title: Parse string at last delimiter from the right
Post by: Cogency on 20 May 2025 10:59:50 PM
Hi all,

I have a string column with varying lengths of text and varying numbers of spaces.  I'd like to isolate the text following the last space at the end of the string.  Any ideas about how I can do that?

Thanks,

Cogency
Title: Re: Parse string at last delimiter from the right
Post by: Cogency on 20 May 2025 11:30:43 PM
e.g. If the text read 'AAAA 12345 BBBB CCCC' I'd like to create a column that shows 'CCCC'.
Title: Re: Parse string at last delimiter from the right
Post by: Cogency on 20 May 2025 11:53:42 PM
I've found a 3-step solution

1.   Reverse = reverse([String_Column])
2.   ParseReverse = substring([Reverse], 1, position(' ', [Reverse])-1)
3.   ReverseParseReverse = reverse([ParseReverse])

It's a bit long-winded but it works.
Title: Re: Parse string at last delimiter from the right
Post by: Andrei I on 25 May 2025 09:47:25 AM
You can use regular expressions:

substring_regex ('\b\w+\W*$', [String_Column])