openrefinegrel

How can I add a string character based on a position in OpenRefine?


I have a column in Openrefine, which I would like to add a character string in each of its rows, based on the position in the string. For example: I have an 8th character number string: 85285296 and would like to add "-" at the fourth place: "8528-5296". Anyone can help me find the specific function in OpenRefine?

Thanks

Tzipy


Solution

  • Possible solution (not sure if it's the most straightforward):

    value.replace(/(\d{4})(.+)/, "$1-$2")
    

    This means : if $1 represents the content of the first parenthesis/group in the regular expression before and $2 the content of the second one, replaces each value in the column with $1-$2.