Reputation: 17372
Does anyone know a repeatable RegEx pattern to capture the words between a comma separated list?
For example:
City,State,Latitude,Longitude
// $1,$2,$3,$4
This is for Find and Replace in an IDE, so the .split
method provided by most programming languages is not a solution. Also no look-aheads / look-arounds please, these are not universally supported.
Clarifications: (1) just need to capture comma-separated words on a single line - not across multiple lines, (2) a solution to the example would be enough.
Upvotes: 0
Views: 2642
Reputation: 27723
If our inputs are as simple as that, your best solution is just fine, and ^
may not be necessary, and these expressions might work:
([^,]*),([^,]*),([^,]*),([^,]*)
([^,]+),([^,]+),([^,]+),([^,]+)
or if start and end anchors are necessary:
^([^,]*),([^,]*),([^,]*),([^,]*)$
^([^,]+),([^,]+),([^,]+),([^,]+)$
jex.im visualizes regular expressions:
Upvotes: 1
Reputation: 17372
This is my best solution at the moment
^([^,]*),([^,]*),([^,]*),([^,]*)$
Upvotes: 0