The reason it doesn't have good performance is that you are compiling the regex equations each time. If you had to do this in a loop, you'd create a grouping of regex objects with each of the different conditions and compare against it. Based on which match you got, you'd take an action. (Using enums and switches or using LINQ functions)
If you're only doing this here and there, then perhaps the performance isn't a big deal?
Overall though, regex's still are pretty zippy with short to medium sized data sets. Over large blocks of text, they can be a bit slow though.




Reply With Quote