VBQ (Very Basic Question): Add a column based on this column (but only with part of the string?)

Hello everybody, I have a rookie question.
I would like to create a column using only a part of data from another column, how can I do it?
To be more specific: I have a column with a complete bibliographic description of books, and I want to extract from this description only the information related to the publisher.
Fortunately, the bibliographic description follows the International Standard Book Description rules, where the information on publishers are always expressed in the same way:

*Title / Author (authors). - City : Publisher ; (eventually) 2nd Publisher, Date of publication. - etc.

So I thought you’d go this way:

if(value.contains (/“: " (.*)”,“/),”",value)

But the result is the exact copy of the original column cell content.
How can I copy in the new column only the information that correspond to the RegEx?
Or maybe I am barking up the wrong tree?
Thanks in advance to anyone who could help me
Bye

Mauro

1 Like

Hi Mauro,

if(value.contains (/": " (.*)","/), "", value)

This code says: when the regex /.../ matches then set the cell to an empty string "", else use value.

What you want is something like:

value.find(/regex/).join(", ")

Note that find will return an array of results, so we have to join them to a string to show them in OpenRefine.

As I am not familiar with the International Standard Book Description rules, I am currently not sure, whether your regular expression is correct as you have a lot of " in the regex, but not in your example.

Hi b2m, it works!
I have now to set better my RegEx, because I found some issues in it (included the use of “” ;-)).
Thank you very much for your help.
See you
Mauro

1 Like