236
236
[DekiScriptParam("string value")] string text,
237
237
[DekiScriptParam("regular expression pattern")] string pattern,
238
238
[DekiScriptParam("ignore case (default: false)", true)] bool? ignorecase,
239
[DekiScriptParam("return text with index (default: false)", true)] bool? withIndex
239
[DekiScriptParam("return text with index (default: false)", true)] bool? withIndex,
240
[DekiScriptParam("return capture groups instead of matched text (default: false)", true)] bool? captures
241
242
ArrayList result = new ArrayList();
242
243
for(var m = Regex.Match(text, pattern, (ignorecase ?? false) ? RegexOptions.IgnoreCase : RegexOptions.None); m.Success; m = m.NextMatch()) {
243
for(var i = 1; i < m.Groups.Count; ++i) {
244
for(var j = 0; j < m.Groups[i].Captures.Count; ++j) {
245
if(withIndex.GetValueOrDefault()) {
246
var info = new Hashtable(StringComparer.OrdinalIgnoreCase);
247
info["text"] = m.Groups[i].Captures[j].Value;
248
info["index"] = m.Groups[i].Captures[j].Index;
251
result.Add(m.Groups[i].Captures[j].Value);
245
// check if user wants to only return capture groups
246
if(captures.GetValueOrDefault()) {
248
// skip over the first group since it represents the entire match
249
for(var i = 1; i < m.Groups.Count; ++i) {
250
var count = m.Groups[i].Captures.Count;
251
for(var j = 0; j < count; ++j) {
252
if(withIndex.GetValueOrDefault()) {
253
var info = new Hashtable(StringComparer.OrdinalIgnoreCase);
254
info["text"] = m.Groups[i].Captures[j].Value;
255
info["index"] = m.Groups[i].Captures[j].Index;
258
result.Add(m.Groups[i].Captures[j].Value);
264
// check if matches should be returned with index positions
265
if(withIndex.GetValueOrDefault()) {
266
var info = new Hashtable(StringComparer.OrdinalIgnoreCase);
267
info["text"] = m.Value;
268
info["index"] = m.Index;