Extract course code from column

55 views
Skip to first unread message

Scott Cowie

unread,
Jun 22, 2016, 10:29:35 PM6/22/16
to OpenRefine
Hi,

I have cells in a column with sentences that include a course code in the format 1234ABC (4 numbers and 3 uppercase letters).
How can I extract this course code to a new column.

Thanks

Thad Guidry

unread,
Jun 23, 2016, 11:46:52 AM6/23/16
to openrefine
Add Column based on this column

Then use GREL:

value.match(/.*(\d\d\d\d[A-Z][A-Z][A-Z]).*/).join("")

The key to this is the Regex Capture Group and the ending empty join to pluck out the value from the array that match() produces.
(I am assuming that you might have characters before or after your pattern... so this uses .*)

More documentation about match() is available here on our wiki, along with more Regex guides: https://github.com/OpenRefine/OpenRefine/wiki/GREL-String-Functions#matchstring-s-regexp-p

--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Cowie

unread,
Jun 24, 2016, 2:20:12 AM6/24/16
to OpenRefine
Thanks Thad, that is exactly what I needed.

Scott.
Reply all
Reply to author
Forward
0 new messages