If you don't know the number of potential matches in a repeated construct, you need a regex engine that supports captures in addition to capturing groups. Only .NET and Perl 6 offer this currently.
In C#:
string pattern = @"@ISNULL\(('([^']*)',?)+\)";
string input = @"@ISNULL('1','2','3','4','5','6')";
Match match = Regex.Match(input, pattern);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
In other regex flavors, you have to do it in two steps. E.g., in Java (code snippets courtesy of RegexBuddy):
First, find the part of the string you need:
Pattern regex = Pattern.compile("@ISNULL\\(('([^']*)',?)+\\)");
// or, using non-capturing groups:
// Pattern regex = Pattern.compile("@ISNULL\\((?:'(?:[^']*)',?)+\\)");
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
ResultString = regexMatcher.group();
}
Then use another regex to find and iterate over your matches:
List<String> matchList = new ArrayList<String>();
try {
Pattern regex = Pattern.compile("'([^']*)'");
Matcher regexMatcher = regex.matcher(ResultString);
while (regexMatcher.find()) {
matchList.add(regexMatcher.group(1));
}