using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(\w{2}).*?(\1)";
string input = @"This is a repeated repeated word.zz zz zz
How would you find pairs of letters that occur twice in a string using regex with Python?
I want to iterate through a list of strings, find the ones that have repeating pairs of letters, and put them into a list. The letters don't need to be the same, the pair just has to repeat, though the letters can be the same.
Ex:
this one has xx twice so I want to keep this string:
xxhgfhdeifhjfrikfoixx
this one would be kept as well, because hd is repeated:
kwofhdbugktrkdidhdnbk
The best I got was to find the pairs: ([a-z][a-z])\1|([a-z])\2
I need to find which pairs repeat in the string.";
RegexOptions options = RegexOptions.IgnoreCase;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx