public Value execute(Value[] args) { ArgumentsCheck.CheckOrOr(2, 3, args.Length, this); string sourceString = args[0].asString(); string regex = args[1].asString(); try{ MatchCollection matchcollection = (new Regex(regex, RegexOptions.IgnoreCase)).Matches(sourceString); ArrayValue matcharray = new ArrayValue(matchcollection.Count); for (int i = 0; i < matchcollection.Count; i++) { matcharray.setValue(i, new StringValue(matchcollection[i].Value)); } if (matchcollection.Count < 1) { matcharray.setValue(0, new StringValue("нет совпадений!")); } return(new ArrayValue(matcharray)); } catch (Exception) { throw new Exception("Неправильное регулярное выражение"); } }
public Value execute(Value[] args) { ArgumentsCheck.CheckOrOr(2, 3, args.Length, this); string sourceString = args[0].asString(); string pattern = args[1].asString(); string replacement = args[2].asString(); return(new StringValue(Regex.Replace(sourceString, pattern, replacement, RegexOptions.IgnoreCase))); }