Tag Archives: patterns

Find files that match multiple patterns in C#

The System.IO.Directory.GetFiles method lets you easily search for files in a directory that match a pattern. Unfortunately it can only search for files that match a single pattern. For example, if you want to find files that match the patterns … Continue reading

Posted in .NET, files | Tagged , , , , , , , , , , , , , , | Leave a comment

Replace text in the lines of a string in C#

This example uses the following code to replace text in the lines of a string. private void btnGo_Click(object sender, EventArgs e) { try { Regex reg_exp = new Regex(txtPattern.Text); lblResult.Text = reg_exp.Replace( txtInput.Text, txtReplacementPattern.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); … Continue reading

Posted in regular expressions, strings | Tagged , , , , , , , , , , , , | 6 Comments

Use regular expressions to rename files within a date range and that match a pattern in C#

This example extends the example Use regular expressions to rename files that match a pattern in C# to let you rename files within a date range. See the previous example for most of the details. This post describes the changes … Continue reading

Posted in files, regular expressions | Tagged , , , , , , , , , , , , | Leave a comment

Use regular expressions to rename files that match a pattern in C#

This example shows how to use regular expressions to rename files. To use the program, enter a directory name and a file pattern. Also enter regular expression find and replace patterns. When you click Preview Changes, the program searches the … Continue reading

Posted in files, regular expressions | Tagged , , , , , , , , , , | 4 Comments