'OpenRefine text transform delete all characters from character "["

I want to delete all characters after the "[" character like the screenshot below:

Schreenshot

How do I achieve this?



Solution 1:[1]

Input examples from the provided screenshot:

  • 189 [122-270]
  • 18 [5.10-6.90]

The easiest way would be to split the column on the separator [ and delete the second column.

The more elaborate way would be to use a regular expression:

value.replace(/\s\[[^\]]+\]/, "")

Play around with https://regex101.com/ or https://regexr.com/ to find out more about how this regular expression works.

Solution 2:[2]

if you want to skip regex complexity, I will use the split function value.split('[')[0] The split() function create an array, and the [0] selector pick the first value of the array.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 b2m
Solution 2 magdmartin