The question is basically what the title says.
I have a string returned by a function and I want to check if it matches against multiple regexes. Then depending on which regex it matched, I want to do different things.
What is the best way to do this if I want performance and simplicity to add new regexes to match against?
One way I came up with was doing an ordinary If Else If, something like this:
This method works I think but it doesn't have good performance what I have heard and it also is kind of messy I think.Code:if(Match(mystring, "regex here")) { //Do something } else if(Match(mystring, "another regex")) { //Do another thing }
So I thought of the switch, that is much better if you want to compare one object against many others. But I don't really know how to use it with a regex in a good way.




Reply With Quote