function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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');
for(integer i=0;i<myMatcher.groupCount();i++){ System.Debug('Match '+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 "