openrefinegrel

Extract text after a string using GREL


I'm trying to add a column based on a column in OpenRefine using GREL.

Here is an example of the original cell data:

https://www.example.com/notice/search/woa/(type)/SOMEWORD

I want to extract:

SOMEWORD

So I need to extract everything after the string (type)/

What is the GREL function for this?


Solution

  • If the 'SOMEWORD' is always the last part of the string, you can also use:

    value.split("/")[-1]
    

    or

    value.rpartition("/")[2]
    

    If you have URLs which don't contain a 'type' where you don't want the same outcome, you can filter the rows to only those containing the type(s) before you do the GREL