Regex r = new Regex(@"^(\1.|^.)+$"); Console.WriteLine(r.IsMatch("aababc")); // True Console.WriteLine(r.IsMatch("1121231234")); // True Console.WriteLine(r.IsMatch("iLoveRegEx")); // False for (int n = 0; n <= 50; n++) { Match m = r.Match("".PadLeft(n)); if (m.Success) { Console.WriteLine("{0} = sum(1..{1})", n, m.Groups[1].Length); } } // 1 = sum(1..1) // 3 = sum(1..2) // 6 = sum(1..3) // 10 = sum(1..4) // 15 = sum(1..5) // 21 = sum(1..6) // 28 = sum(1..7) // 36 = sum(1..8) // 45 = sum(1..9)
Regex r = new Regex("=([^;]*);"); Match m = r.Match(yourData); while (m.Success) { string match = m.Groups[1]; // match should be the text between the '=' and the ';'. }
public static string NameValueFromString(string input) { string returnValue = null; if (!String.IsNullOrWhiteSpace(input)) { Regex nameValueExpression = new Regex(@"name=""[^""]*""", RegexOptions.IgnoreCase); Match match = nameValueExpression.Match(input); if (match.Success) { Regex valueExpression = new Regex(@"""[^""]*"""); returnValue = valueExpression.Match(match.Value).Value.Trim('"'); } } return returnValue; }
Regex r = new Regex("^data:(.*?);base64,(.*?)$"); Match m = r.Match(fileData); if(m.Success) { string mimeType = m.Groups[1].Value; }
Regex test = new Regex("^(?:(?<ch>[A-Za-z])|(?<num>[9-0])){8,20}$"); Match m = test.Match(input); if (m.Success && m.Groups["ch"].Captures.Count > 1 && m.Groups["num"].Captures.Count > 1) { // It's a good password. }
Regex rx = new Regex("(.*?)b(.*?)d(.*?)"); Match match = rx.Match("abcde"); string found = match.Value;
File fileDir = new File("DIRECTORY OF FILE"); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileDir), "UTF8")); String str; Regex pageBreak = new Regex("(^.*)(\f)(.*$)") while ((str = in.readLine()) != null) { Match match = pageBreak.Match(str); bool pageBreakFound = match.Success; if(pageBreakFound){ String textBeforeLineBreak = match.Groups[1].Value; //Group[2] will contain the form feed character //Group[3] will contain the text after the form feed character //Do whatever logic you want now that you know you hit a page boundary } System.out.println(str); } in.close();
while (startat < all.Length) Match match = reg1.Match(all, startat); if (!match.Success) break;