Combining expressions

Ideally, I want to be able to apply two expressions in the same step. The First replace is to remove new lines and the second to replace redundant spaces before a comma where they occur.

value.replace(/\n/," ").replace(" ,",",")

I have tried this, which does not have syntax error but does not achieve the required result. Both expressions of course work individually.

So in my tests your expression does exactly what you describe (removes linebreaks and redundant spaces before a comma).

Could you give an example text snippet where the expression does not work for you?

Also what version of OpenRefine are you using?

You are quite correct. I had an extra space in the actual text so I had to add that to the expression too!

Is there a method of displaying hidden characters i.e. like a 'pilcrow' button?

| myfta
September 17 |

  • | - |

Is there a method of displaying hidden characters i.e. like a 'pilcrow' button?

Not currently, but there is an open feature request: https://github.com/OpenRefine/OpenRefine/issues/1286

If you're working with normal-ish text, using the Edit Cells -> Commons Transforms -> Trim leading and trailing whitespace and Collapse consecutive whitespace functions are useful normalizations to start out with. The latter also takes care of normalizing things like non-breaking spaces, half-width spaces, etc into a single plain space character.

Tom

Hi @myfta,

You could try this: value.replace(/\n/," ").replace("\s+,",",")

\s = any white space (like space or tab…)
+ = found once or many time

Regards, Antoine

You could try this: value.replace(/\n/," ").replace("\s+,",",")

Regexs need to be surrounded with slashes instead of quotes, so this will need to be:

value.replace(/\n/," ").replace(/\s+,/,",")

Tom

1 Like

Our full documentation for Regular Expression support throughout OpenRefine is detailed here:

I made a PR that also updates and clarifies things a bit better in our Regex docs paragraphs in regards to the syntax.