import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)";
final String string = "Column,Row,Value,Column Title,Question,Answer\n"
+ "A,1,100,Comics,\"This series following a team of mutants, was actually cancelled during it's first run and did not reach its popular status until a revival severla years later.\",X-Men\n"
+ "A,2,200,Comics,This demonic hero has a big gun and an even bigger right fist.,Hellboy\n"
+ "A,3,300,Comics,This mostly self-published series follows three osteo-minded cousins through a series of misadventures.,Who is...\n"
+ "A,4,400,Comics,\"Superman may be considered the first, but this magical superhero also debuted in Action Comics #1, 7 pages after Superman.\",Zatara\n"
+ "A,5,500,Comics,\"Sharing the alias of a few villainous iterations in the main comics, this character from the \"\"What If?\"\" line of comics is a spider bitten by a radioactive human.\",Webster Weaver / Man-Spider\n"
+ "B,1,100,Disney,\"One of these per day will keep the doctor away, but a poisoned one requires a visit from nobility.\",An Apple\n"
+ "B,2,200,Disney,\"This character, one of seven of his kind, is the only one who's name is not an adjective.\",Doc\n"
+ "B,3,300,Disney,This kitchen essential is the weapon of choice for Rapunzel.,A cast iron frying pan\n"
+ "B,4,400,Disney,Billy Joel lends his voice to this canine character.,Dodger\n"
+ "B,5,500,Disney,This is the last animated feature to be produced by Walt Disney until his death in 1966.,The Jungle Book\n"
+ "C,1,100,MTG,\"A player of the game is called this, eventually added as a card type.\",A Planeswalker\n"
+ "C,2,200,MTG,Much of early Magic is set on this plane.,Dominaria\n"
+ "C,3,300,MTG,This space between planes is also the original home of the Eldrazi.,The Blind Eternities\n"
+ "C,4,400,MTG,\"Often mistakenly used when referring to double face cards, this mechanic originated in Kamigawa block\",Flip Cards\n"
+ "C,5,500,MTG,This base set is the first set designated with a numbered release.,Fourth Edition\n"
+ "D,1,100,Pokemon,\"\"\"Ay cutie, are you an electric rodent or can I get a...\"\"\",Pikachu\n"
+ "D,2,200,Pokemon,\"In the card game, there are this many basic energy types\",Nine\n"
+ "D,3,300,Pokemon,This fighting type pokemon's english name is partially inspired from a famous action comedy movie star.,Hitmonchan\n"
+ "D,4,400,Pokemon,\"In the original anime, albeit being a generation 2 pokemon officially, this is the first legendary Pokemon Ash Ketchum sees.\",Ho-oh\n"
+ "D,5,500,Pokemon,\"As of generation 9, this is the most common type of Pokemon\",Water\n"
+ "E,1,100,Board Games,This generic wooden piece is usually used to represent a person.,A meeple\n"
+ "E,2,200,Board Games,This board game changed a rule to allow proper nouns and it has been downhill ever since.,Scrabble\n"
+ "E,3,300,Board Games,This board game takes its name and theme from a famous road in Japan.,Tokaido\n"
+ "E,4,400,Board Games,The commonly used standard playing card deck has origins in this Europeon country. ,France\n"
+ "E,5,500,Board Games,\"This is what a super nerd calls a 20-sided die, also known as it's geometric name.\",icosahedron\n"
+ "F,1,100,\"Words that rhyme with \"\"piss\"\"\",A cat or a snake will perform this when upset.,Hiss\n"
+ "F,2,200,\"Words that rhyme with \"\"piss\"\"\",You may give one of these to someone you love.,Kiss\n"
+ "F,3,300,\"Words that rhyme with \"\"piss\"\"\",\"When class is over, the teacher will perform this action.\",Dismiss\n"
+ "F,4,400,\"Words that rhyme with \"\"piss\"\"\",\"If you stare into this for too long, it will stare back at you.\",Abyss\n"
+ "F,5,500,\"Words that rhyme with \"\"piss\"\"\",When you remember fondly.,Reminisce";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html