Bogdan Emil Mariesan
Bogdan Emil Mariesan

Reputation: 5647

Split line comma at end of line and exclude special cases

Hi i have the following group:

`group_id` int(10) unsigned NOT NULL,
`right_id` int(10) unsigned NOT NULL,
`group__right_value` enum('allow','deny') NOT NULL DEFAULT 'deny',
KEY `group_id` (`group_id`),
KEY `right_id` (`right_id`)

And i expected the strings to always end with a comma so a did a split based on that. Now i've noticed that in some cases like above the commas should be ignored and the values left as they are:

enum('allow','deny')

How should i exclude the commas between brackets when doing the split?

EDIT:

The expected result should be:

  1. 'group_id' int(10) unsigned NOT NULL,
  2. 'right_id' int(10) unsigned NOT NULL,
  3. 'group__right_value' enum('allow','deny') NOT NULL DEFAULT 'deny',
  4. KEY 'group_id' ('group_id'),
  5. KEY 'right_id' ('right_id')

Upvotes: 0

Views: 183

Answers (2)

user23031988
user23031988

Reputation: 330

http://regexr.com?3579s

Hope this help [^\,]+(\,\')?[^\,]+

Upvotes: 0

Ja͢ck
Ja͢ck

Reputation: 173642

Matching a comma at the end of the string is done with an anchor:

/,$/m

The /m modifier is used to enable multiline mode, in which $ will match the end of the line instead of the standard end-of-subject.

Upvotes: 1

Related Questions