Do you need to manipulate a text file with find-and-replace tool? You may use our online tool to find-and-replace a string or regular expression with a static text, and create a desired text document. You may copy resulting content into the original window with a click of a button, and continue to find-and-replace strings (or regex) until you arrive at the desired content.

Upload

Find String

OR

Find RegEx

You may use \n to enter carriage-return, and \t to enter a TAB.

Replacement String

What is regular expression (RegEx)?

A regular expression, often referred to as regex, is a sequence of characters that forms a search pattern. It is a powerful tool used for matching and manipulating strings of text based on specific patterns.

Regular expressions consist of a combination of ordinary characters (such as letters and digits) and special characters (metacharacters) that have special meanings. These metacharacters allow you to define complex search patterns, including matching specific characters, character ranges, repetitions, alternatives, and more.

Regular expressions are widely used in programming languages (php, perl, python), text editors, (vi, vim) and command-line tools (awk, sed) for tasks such as data validation, text search and replace, parsing, and pattern matching.

For example, the regular expression pattern "^[A-Za-z]+$" can be used to match a string that consists of one or more alphabetical characters, while the pattern "\d{2}-\d{2}-\d{4}" can match a date in the format "dd-mm-yyyy".

Learning and mastering regular expressions can be a valuable skill for tasks involving text processing and manipulation, and especially necessary skill for softengineers who work with scripting languages. By learning and understanding metacharacters and how they apply to pattern matching, you'll be able to master regex in a few days.

Patterns

A regular expression uses a pattern to match a string. There are literal characters which matches exact character, and wildcard characters that matches a variety of characters. Also, there are symbols that match number of occurances (?, + and *). To give you a flavor of how regular expression works, here are some concepts used to match a text.

Meta Character Operation Example Description
| Or apple|orange|pear Matches apple, orange, or pear
() Group gr(a|e)y Matches grey or gray
. Any char a.c Matches abc, adc, aMc
? 0 or 1 occurance colou?r Matches color or colour
* 0 or more occurance xyz* Matches xy, xyz, xyzz
+ 1 or more occurance xyz+ Matches xyz, xyzz, xyzzz
- Range with bracket [a-z] Matches a, b, through z
[] Or 1 character [abc] Matches a, b or c
[^ ] Not contained [abc] Matches any char but a, b or c
^ Beginning of string ^abc Matches starting with abc
$ End of string xyz$ Matches string ending xyz
\t Tab \t Matches tab
\n New Line \n Matches new line
\n, n=1..9 Match nth item (abc|xyz)\1 Matches abcabc, abcxyz
{n}, n=1..9 match n times a{3} Matches aaa