开发者

Regex to match 1 2 3 4,5,6

I have a file with lines in the following format

1 2 3 4,5,6

First three delimited by space and the last three delimited by commas. As an example i've gi开发者_如何转开发ven 1-6 but the values can be alphanumeric value. Can someone help me with a regular expression to match the entire line to extract the 6 values?

In Java i can use this regex - line.split("[ ,]") and it works, but I am using Hadoop Pig and I need to pass the regex to a method called PigStorage(), which expects the regex to match the entire string.

Here is the doc from Pig-

"Pig does support regular expression matching via the matches keyword. It uses java.util.regex matches which means your pattern has to match the entire string (e.g. if your string is "hi fred" and you want to find "fred" you have to give a pattern of ".*fred" not "fred")."

So I want a regex to match the entire line, and extract the 6 values. Any help?


Maybe you need use capture group here:

    Pattern p=Pattern.compile("(\\d)\\s(\\d)\\s(\\d)\\s(\\d),(\\d),(\\d)");
    Matcher m=p.matcher("1 2 3 4,5,6");
    int cnt=m.groupCount();
    for(int i=1;i<=cnt;++i)
    System.out.println(m.group(i));


(\w+) (\w+) (\w+) (\w+),(\w+),(\w+)

maybe?


Try this one:

([^ ]+){4}([^,]+){2}


How about:

\S+ \S+ \S+ \S+,\S+,\S+
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜