in reply to Nth match.
Someone tell me to use (?key). Is it right?
Assuming that the quotes cannot be nested, it is possible to write a regex for this, yes. However, it's going to be a fairly complicated regex, and if you aren't comfortable using the more advanced regex features, then you're better off using a module, especially if quoting can use either single or double quotes and embed the other, and other such things you might not think of when you write the regex but could run into later. A well-tested module off the CPAN will already hande such things, if it's a common CSV format you're parsing.
So use the module.
For purely educational purposes, the regex could look something like this untested monstrosity:
/^(?:(?:["][^"]*["]|['][^']*[']|[^,]*),){3}(["][^"]*["]|['][^']*[']|[^,]*),/Hey, at least there are no lookbehind assertions. Nonetheless, when you think about trying to maintain code with stuff like that in it, you will understand why we say, "use a module from the CPAN". No need to maintain what somebody else is already maintaining.
|
|---|