Google Refine中的Value.match()正则表达式 [英] Value.match() Regex in Google Refine
问题描述
我正在尝试从Google Refine的一列中提取数字序列.这是我执行此操作的代码:
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]
我列中的数据格式为
abcababcabc 1234566 abcabcbacdf
结果为空".我不知道为什么!!如果我尝试使用\w
代替\d
,则它也为null.
The results is "null". I have no idea why!! It is also null if instead of \d
I try \w
.
推荐答案
OpenRefine不会像某些系统一样(并且可能会期望)在模式的末尾添加隐式通配符.尝试以下模式:
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]
您需要在通配符上使用惰性/非贪婪的限定符(即问号),以免它们也不会占用您的一些数字.如果仅使用/.*(\d+).*/
,则只能匹配一个数字,因为其余数字将由.*模式占据.
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.
这篇关于Google Refine中的Value.match()正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!