问题
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