Good morning,
Let’s say I have the following code, which attemps to remove any whitespace from every string in a given list:
foreach (String StrTmp in SomeList)
Regex.Replace(StrTmp, @"\p{Z}", "", RegexOptions.Compiled)
Since the documentation of RegexOptions.Compiled says that “This yields faster execution but increases startup time”, I would like to know if this increased startup time refers to the whole program’s startup time or if it refers to the startup of every Regex.Replace function call inside the cycle, thus making the whole cycle slower.
By the way… Isn’t there any Regex.Remove(.,.) command to remove every ocurrence of a given regular expression? Basically this is the same as above, but could be shorter and more elegant.
Thank you very much.
It refers to the regex compile time. But the Compiled option is designed for regexes that are created once and used often, so it makes most sense to make it once outside the loop and reuse it.