id like to do something like
foreach (Match match in regex) { MessageBox.Show(match.ToString()); }
Thanks for any help...!
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
$ means "Match the end of the string" (the position after the last character in the string).
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
There is a RegEx.Matches
method:
foreach (Match match in regex.Matches(myStringToMatch)) { MessageBox.Show(match.Value); }
To get the matched substring, use the Match.Value
property, as shown above.
from MSDN
string pattern = @"\b\w+es\b"; Regex rgx = new Regex(pattern); string sentence = "Who writes these notes?"; foreach (Match match in rgx.Matches(sentence)) { Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With