Reputation: 2385
I have a row of data that is split by tabs. I want to do a counted matching: first three are in group 1, second three are in group 2, and last one in group 3.
0 0 1998-09-21 CD O O B-Num
I'm not an expert in regex but I came up with this:
^(\S*)[\t,]*(\S*)[\t,]*(\S*)[\t,]*(\S*)[\t,]*(\S*)[\t,]*(\S*)[\t,]*(\S*)[\t,]*(.*)$
This will only split everything into seven pieces, which does not meet the requirement..anyone knows how to do tasks like this?
Upvotes: 0
Views: 42
Reputation: 71598
You can change the way you're capturing a little to this:
^(\S*[\t,]*\S*[\t,]*\S*)[\t,]*(\S*[\t,]*\S*[\t,]*\S*)[\t,]*(\S*)$
^---------------------^ ^---------------------^ ^---^
Also, you might want to change some of the quantifiers to +
. having all *
means that it will also attempt to match an empty string.
Upvotes: 1