A question of string manipulation

Hi there!

I have a string column including file location and date&time information.
Now I need to convert this string like the following image.

string%20convert

Please notice the Date&time part of the last 3 rows contains different hour expression (2 digit).

I tried a lot to use Column Expressions Node to handle this manipulation but not successful.
Could you please give some advice to this question?

Here you can find the sample data.
StringConvert.xls (27 KB)

Thanks in advance.

1 Like

Hi,

To get the format in “StringTo” column from the “String” column, use this expression in a String Manipulation node:
regexReplace($String$, ".*-", "")

If you want to use the Column Expressions node instead:
regexReplace(column("String"), ".*-", "")

Best,
Armin

5 Likes

It worked! @armingrudd
Currently I don’t understand why it worked, need to study regex expression…

Thank you!

2 Likes

.*- selects all the string before the dash character and the dash itself and since there are multiple dash characters in the string, everything to the last one is selected. If you put a caret “^” at the beginning of the regex and the ? after * ( ^.*?-) then it only selects the first match which means everything before the first dash and the first dash itself will be selected.

:blush:

2 Likes

Thanks for your addition information. Completely understood! :blush:
I have also found some article on web for learning regex expression but it seems different in different tools :shushing_face:. I will read the link from you in advance.

Many thanks!

2 Likes

I have created the following regex expression in Column Rename (Regex) node:

(^.*_)

Target Column name is like: ABCD_EFG_001_00
The purpose is to match the string before the first “_”, so I consider ABCD should be selected.
But it doesn’t work ( all characters in the string has been selected).

Does Column Rename (Regex) node have different expression?

Thanks! :smile:

First, I’m sorry about a mistake in my previous post which I just edited.

You have to match the whole column name then if you want to use the first part (ABCD) in the replacing name, you should put the regex corresponding to the string in parentheses:
(^.*?)_.*

Now you can use $1 in replacement which stands for ABCD in this example.

:blush:

P.S.

Regex is the same in all nodes except when you are using \ to escape special characters. If you are using it in a expression inside e.g. a String Manipulation, you have to use another \ to escape the \.
But if you are using it in configuration settings, you don’t need to do that. That’s all.

1 Like

Understood! Thanks! :relaxed::handshake:

1 Like

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