0

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.

Joey
  • 344,408
  • 85
  • 689
  • 683
darshan
  • 1,230
  • 1
  • 11
  • 17

2 Answers2

0

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/ ) )
stema
  • 90,351
  • 20
  • 107
  • 135
Stuart
  • 574
  • 6
  • 15
  • I want to do exactly this: I have a URL: http://www.bing.com/search?q=lenovo+outlet&form=MSNH14&qs=AS&sk=AS2&pq=lenovo&sp=3&sc=8-6 , I want to extract value of q parameter from url. – darshan May 21 '12 at 11:47
  • That's going a bit farther. First, to extract a value, you need to use parenthesis to do a regexp capture. Also, if you want to turn the result (an array) into the array's contents, you pull out the value at index position zero [0]. With that in place, you just need to play with the regexp to pull everything following the "q=" up to any possibly next ampersand. Here's one way that's working for me with sample data: value.match( /.*search\?q=([^&]+).*/ )[0] – Stuart May 21 '12 at 13:19
0

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]
Ashley Davis
  • 9,896
  • 7
  • 69
  • 87