Value.match() Regex in Google Refine

浪尽此生 提交于 2019-12-04 22:32:56

问题


I am trying to extract a sequence of numbers from a column in Google Refine. Here is my code for doing it:

value.match(/[\d]+/)[0]

The data in my column is in the format of

abcababcabc 1234566 abcabcbacdf

The results is "null". I have no idea why!! It is also null if instead of \d I try \w.


回答1:


OpenRefine doesn't add implicit wildcards to the end of the pattern as some systems do (and as one might expect). Try this pattern instead:

value.match(/.*?(\d+).*?/)[0]

You need the lazy/non-greedy qualifier (ie question mark) on the wildcards so that they don't gobble up some of your digits too. If you just use /.*(\d+).*/ you'll only match a single digit because the rest of them will be taken by the .* pattern.

Full documentation for the implementation can be seen in Java's Pattern class docs.



来源:https://stackoverflow.com/questions/17896772/value-match-regex-in-google-refine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!