Substrings with regular expression
Hi,
since I always forget this one, I'll post it here.
I'm tired of always using native c# code to perform substring selects on string values. This produces lots of code. I've replaced it with regular expressions
Let's suppose we have the following string value
string expr = "This is a test message where I want to extract the value test out of [test]";
We can use this code:
string value=
Regex.Match(expr ,@"(?<=\[).*(?=\])").Value;
value will be test !!
since I always forget this one, I'll post it here.
I'm tired of always using native c# code to perform substring selects on string values. This produces lots of code. I've replaced it with regular expressions
Let's suppose we have the following string value
string expr = "This is a test message where I want to extract the value test out of [test]";
We can use this code:
string value=
Regex.Match(expr ,@"(?<=\[).*(?=\])").Value;
value will be test !!
Labels: Regular Expressions
