How to Extract the first letter and the last letter

Hi all,

I would like to know how to extract the first letter and the last letter?

Also, if I want to extract the letters after “@”, how can I do it?

Here is my data set sample

aabbccdd@56asdfsdaf
ssfnioasdf@asdfsdfg
ssfnio@hfbnv

Thanks in advance!

Hi @HKUser, can I just check, when you say first and last letter, will your data always have a letter at the beginning and end? I assume that you really do mean “letter” rather than just “character” so you are trying to filter out other characters?

1 Like

To extract just letters, the simplest way I found was a java snippet that uses a regex replace to remove any non-alphabetic characters. Java could of course be used to then do all of what you need, but in an attempt to keep things reasonably generic, I have used a java snippet just to perform letter-only extraction and combined it with other nodes.

For the “first and last” letters, the java is done first, and then other nodes perform the substring.

For “letters after the @”, first off, I use other nodes to grab the entire substring after the @ and then perform the java snippet to grab just the letters.

It could be written differently (without the use of the getCell method), but the java snippet is written here in a way that makes it easy just to slot in the name of the column to be processed as a string literal:

String columnToProcess="column1";	
out_LettersOnly = this.getCell(columnToProcess,tString).replaceAll("[^A-Za-z]+", "");

so simply replace “column1” with the name of your column.


Extract Letter-Only substrings.knwf (23.9 KB)

2 Likes

for first and last letters you could use regex
(\w)[\w@]+(\w)
I “borrowed” @takbb 's hard work for a quick check. Kudos. All credits to him.
br

1 Like

Sorry for my unclear description!

Actually I want to hide the characters like the following

aabbccdd@56asdfsdaf → axxxxxxd@56asdfsdaf
ssfnioasdf@asdfsdfg → sxxxxxxxxf@asdfsdfg
ssfnio@hfbnv → sxxxxxo@hfbnv

Hi @HKuser , I put a workflow together that will do what you want:
aabbccdd@56asdfsdaf → axxxxxxd@56asdfsdaf
ssfnioasdf@asdfsdfg → sxxxxxxxxf@asdfsdfg
ssfnio@hfbnv → sxxxxxo@hfbnv

Input:
image

Result:
image

And here’s the workflow: Obfuscate email user.knwf (9.2 KB)

5 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.