+ Start a Discussion
Paul.FoxPaul.Fox 

Regex Patter to match characters in quotes

I'm trying to parse a csv file and having trouble getting the pattern to match correctly.

 

This section of code has been formatted to work in the system log, so any helpful people can try it out and make their changes.

 

This pattern works in the web-based regex tester I've used, but it doesn't work in Salesforce. Not sure what I'm doing wrong.

 

pattern myPattern = pattern.compile('(".*?")'); 
matcher myMatcher = myPattern.matcher('Joe,0%,0%," $48,623 "," $48,623 ",0,29468,39782,48623,1');
System.assert(myMatcher.matches());
for(integer i=0;i<myMatcher.groupCount();i++){ System.Debug('Match '+i+': '+myMatcher.group(i));}

If the pattern works correctly, the output should look like this:

Match 0: Joe,0%,0%," $48,623 "," $48,623 ",0,29468,39782,48623,1
Match 1: " $48,623 "
Match 2: " $48,623 "