Carl3003
asked on
using regex to replace multiple strings at once ?
To replace multiple strings , i use the expression Regex("asdf sdfd sdfd",str1, someString) mulptiple times like
Regex("asdf sdfd sdfd",str2, someString)
Regex("asdf sdfd sdfd",str3, someString)
Regex("asdf sdfd sdfd",str4, someString)
I want to find a way to combine all these statements into just one..like this one
Regex("asdf sdfd sdfd", any of (str1, str2, str3, str4) , someString)
in other words to replace any occurrence of str1, str2, str3....
Thanks
Regex("asdf sdfd sdfd",str2, someString)
Regex("asdf sdfd sdfd",str3, someString)
Regex("asdf sdfd sdfd",str4, someString)
I want to find a way to combine all these statements into just one..like this one
Regex("asdf sdfd sdfd", any of (str1, str2, str3, str4) , someString)
in other words to replace any occurrence of str1, str2, str3....
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can call Replace with a MatchEvaluator delegate. The delegate will be called on every match and you can decide how you want to replace the matched string (or if you want to store it somewhere else).