Ejemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            var options = RegexOptions.None;

            if (Compiled)
            {
                options = options | RegexOptions.Compiled;
            }
            if (CultureInvariant)
            {
                options = options | RegexOptions.CultureInvariant;
            }
            if (ECMAScript)
            {
                options = options | RegexOptions.ECMAScript;
            }
            if (ExplicitCapture)
            {
                options = options | RegexOptions.ExplicitCapture;
            }
            if (IgnoreCase)
            {
                options = options | RegexOptions.IgnoreCase;
            }
            if (IgnorePatternWhitespace)
            {
                options = options | RegexOptions.IgnorePatternWhitespace;
            }
            if (Multiline)
            {
                options = options | RegexOptions.Multiline;
            }
            if (RightToLeft)
            {
                options = options | RegexOptions.RightToLeft;
            }
            if (Singleline)
            {
                options = options | RegexOptions.Singleline;
            }
            var result = Regex.Replace(Input.Get(context), Pattern.Get(context), Replacement.Get(context), options);

            Result.Set(context, result);
        }
Ejemplo n.º 2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            var invalid     = false;
            var pattern     = Pattern.Get <string>(executionContext);
            var replacement = Replacement.Get <string>(executionContext);
            var text        = Text.Get <string>(executionContext);
            var result      = text;

            try
            {
                var regex = new Regex(pattern);
                result = regex.Replace(text, replacement);
            }
            catch (ArgumentException)
            {
                invalid = true;
                // Syntax error in the regular expression
            }

            InvalidRegularExpression.Set(executionContext, invalid);
            Result.Set(executionContext, result);
        }