I have the following:
Text:
field id=”25″ ordinal=”15″ value=”& $01234567890-$2000-“
Regular Expression:
(?<=value=”).*(?=”)
Replacement String:
& $09876543210-$2000-
When I run Regex Replace in Expresso – it crashes the application.
If I run Regex.Replace in C#, I receive the following Exception:
ArgumentException
parsing “& $01234567890-$2000-” – Capture group numbers must be less than or equal to Int32.MaxValue.
A
$Nin the replacement pattern refers to the Nth capture group, so the regex engine thinks you want to refer to capture group number “09876543210” and throws theArgumentException. If you want to use a literal$symbol in the replacement string then double it up to escape the symbol:& $$09876543210-$$2000-Also, your pattern is currently greedy and may match more than intended. To make it non-greedy use
.*?so it doesn’t end up matching beyond another double quote later in the string, or[^"]*so that it matches everything except a double quote. The updated pattern would be:@"(?<=value="").*?(?="")"or@"(?<=value="")[^""]*(?="")". If you never expect the value attribute to be empty I suggest using+instead of*in any of the patterns to ensure it matches at least one character.