Google Refine: Regular expression not working

1.3k views Asked by At

I need to match a regular expression for a text facade in google refine. I tried the expression and it didn't work. Then I tried a simple case of matching string lenovo in www.lenovo.com using

value.match(/lenovo/)

in some of the rows my value takes value www.lenovo.com ,

How come such a simple string match, not working in Google refine. I'm running on windows.

Please let me know if I'm doing any obvious syntax errors.

2

There are 2 answers

2
Stuart On

What are you getting back, and what do want to get back?

The return value of the match() function is either null for no-match or an array

The help tab says:

match (string or regexp) returns: array of strings Returns an array of the groups matching the given regular expression

For an input value of "lenovo",
this function: value.match( /lenovo/ )
should return this value: []

Do you want to turn this into a True/False value for your facet, to test the presence/absence of that text string? You could do something like this:

isNotNull( value.match( /lenovo/ ) )
0
Ashley Davis On

You need to make a group in your regular expression, eg this:

 value.match(/lenovo/)

which results in:

 []

should be:

 value.match(/(lenovo)/)

which results in:

 ["lenovo"]

Which is probably more like what you want. You can then index the array to retrieve the string value:

  value.match(/(lenovo)/)[0]