cancel
Showing results for 
Search instead for 
Did you mean: 

Extract only the text beyond the last delimiter in a string

Former Member
0 Kudos

I am trying to extract only the text beyond the last delimiter in a string, and drop everything else.

For example:

AlphaText1:AlphaText2:AlphaText*

AlphaText1:AlphaText2:AlphaText3:AlphaText*

I only want the portion I have named AlphaText*, which may be following the 2nd, 3rd, or even 4th delimiter, which is ":".

I know I can split the data into 3, 4, or more columns, but I don't want anything but the alpha-numeric content that follows the last delimiter in the string.

Does anyone know what formula to use for this purpose?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183045
Contributor
0 Kudos

Hi there!

A bit cryptic but more or less a "formula" is to use find with regex.

FIND REGEX ':([^:]+)$' in yourInputString

SUBMATCHES lastAlphaValue.

" lastAlphaValue contains your desired string part

Hope it helps,

Andreas

Former Member
0 Kudos

I'm just slightly confused as to what to type as part of the formula, so I'll take a shot at a different example:

12345:12699:widgets_w/gadgets:12699-AA-BBBB

22345:22499:22499-AA-CCCC

CONFIGABCDE:ZBC999:ZBC999-QQ1-A53

All three of the examples above are contained in the data field {ItemFullName},so my guess as to what the formula would look like given your reply is as follows:

   FIND REGEX':([^:]+)$' in {ItemFullName}

   SUBMATCHES lastAlphaValue

Is this correct?  The desired part of my alpha-numeric string is usually different and can be variable length.

The results I would be expecting would be:

   12699-AA-BBBB

   22499-AA-CCCC

   ZBC999-QQ1-A53

Thanks!

abhilash_kumar
Active Contributor
0 Kudos

Hi Clayton,

Create a formula with this code:

local stringvar array s := split({Your Text Field}, ':');

s[ubound(s)];

-Abhilash

former_member183045
Contributor
0 Kudos

Sorry I did not realized that the question is  in the crystal reports area. My solution is only for ABAP and therefore here mot applicable

Former Member
0 Kudos

That seems to have worked perfectly!  Thank you very much!

Former Member
0 Kudos

I appreciate you taking the time to try and help anyway!

Thanks! 

Answers (0)