tags:

views:

36

answers:

2

I have a huge CSV list that needs to be broken up into smaller pieces (say, groups of 100 values each). How do I match 100 lines? The following does not work:

(^.*$){100}
A: 

You don't need regex for this, there should be other tools in your language, even if there is none, you can do simple string processing to get those lines.

However this is the regular expression that should match 100 lines:

/([^\n]+\n){100}/

But you really shouldn't use that, it's just to show how to do such task if ever needed (it searches for non newlines [^\n]+ followed by a newline \n repeated for {100} times).

aularon
This assumes lines end with `\n`, which they not necessarily do.
Tomalak
Yes, I meant that just as an example to show how he would do such thing, nothing more. But you are right, I should have also referred to this fact.
aularon
+1  A: 

If you must, you can use (flags: multi-line, not global):

(^.*[\r\n]+){100}

But, realistically, using regex to find lines probably is the worst-performing method you could come up with. Avoid.

Tomalak