
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 0.99 KB | hits: 10 | expires: Never
How to find a string that is delimited by a certain start and end character
string testingString = "stack $over| flow $stack| exchange";
var pattern = @"(?$.*?|)"; // also tried @"$[^|]|"
foreach (var m in System.Text.RegularExpressions.Regex.Split(testingString, pattern)) {
Response.Write(m );
}
// output == stack $over| flow $stack| exchange
string testingString = @"stack $over| flow $stack| exchange";
MatchCollection result = Regex.Matches
(testingString,
@"
(?<=$) # This is a lookbehind, it ensure there is a $ before the string
[^|]* # Match any character that is not a |
(?=|) # This is a lookahead,it ensures that a | is ahead the pattern
"
, RegexOptions.IgnorePatternWhitespace);
foreach (Match item in result) {
Console.WriteLine(item.ToString());
}
Regex t = new Regex(@"$([^|]+)|");
MatchCollection allMatches = t.Matches("stack $over| flow $stack| exchange");