regex split expression in parentheses

I have int: 100(2), 300(4), 90(1) and I want to include expression in parentheses in new column

Hi.
Is it always 3 values? In that case you can use the String Manipulation node with following expression to extract the first value:

regexReplace($yourcol$, "^[0-9]+\(([0-9]+)\).*", "$1")

For the second value, add another String Manipulation node with the following expression:

regexReplace($yourcol$, "^[0-9]+\([0-9]+\), [0-9]+\(([0-9]+)\).*", "$1")

and finally for the last one:

regexReplace($yourcol$, "^[0-9]+\([0-9]+\), [0-9]+\([0-9]+\), [0-9]+\(([0-9]+)\).*", "$1")

If you have more elements, you can use a Cell Splitter to split by comma and a Column List Loop Start to extract the information from the split cells in a loop.
Kind regards,
Alexander

4 Likes

@AlexanderFillbrunn And what if i want to delete part of string containing 1 in parentheses. e.g.
400(3), 300(1), 500(2)
and I want:
400(3), 500(2)

and (1) may show up in each position in string

Hi,
in that case I would use a Column Expressions node with the following expression:

/^([0-9]+\([0-9+]\))(, ([0-9]+\([0-9]+\)))?(, ([0-9]+\([0-9]+\)))?$/g.exec(column("column1"))
.filter(function(m, i) { return i%2 == 1 && m.indexOf("(1)") == -1; })
.join(",")

followed by a Cell Splitter that splits the result by comma.
Alternatively, if you have just one row, you can use a Cell Splitter first, then transpose the table, use a Row Filter to filter out the wildcard pattern *(1) and then transpose back.
Kind regards,
Alexander

2 Likes

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