Hi,
I would like to truncate a column at the last occurrence of special characters.
For eg:
Is there any regex to do this?
Hi,
I would like to truncate a column at the last occurrence of special characters.
For eg:
Is there any regex to do this?
Hi @soumya123 ,I don’t have a clear definition of “special characters” (I know what they are but don’t know definitively which characters you would treat as special characters) so I’m treating it as any “non-alphanumeric” characters. You can replace this with an specific set of characters if necessary.
I think the following describes in different words what I think you are trying to return:
A regex that will capture a string up to, but not including, an end marker
where the end marker is defined as :
(a) the first non-alphanumeric character ("special character") that is followed only by an optional number (0, 1 or many) of non-alpha numeric characters followed by a sequence of 0, 1 or many alphanumeric characters
or
(b) the line terminator
The following regex works in my tests, when used with the Regex Split node:
(.*?)([^a-zA-Z0-9][^a-zA-Z0-9]*[A-Za-z0-9]*|$)
notes:
(.*?)
= string to be captured followed by
either
[^a-zA-Z0-9]
= first non-alpha-numeric character followed by
[^a-zA-Z0-9]*
= an optional sequence of non-alphanumeric characters followed by
[A-Za-z0-9]*
= an optional sequence of alphanumeric characters
or
$
= the line terminator
truncate string at last special character onwards.knwf (11.0 KB)
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.