Regular expression is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt.
But you can do much more with regular expressions. In a text editor like Notepad++, you could use the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b to search for an email address. Any email address, to be exact. A very similar regular expression can be used by a programmer to check if the user entered a properly formatted email address.
In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.
Reference regex link: https://regexr.com/
For example:
Example one:
If you want to change all below value in your editor, you can do it easy with find regular expressions
I have below value as my text, I want to change all val="xxx" to xxx value.
val="4"
val="403"
val="200"
val="201"
val="116"
val="15"
Regular Expression
Find: .*"(\d+)"
Replace: $1
Note
Remember check into Regular expression checkbox to notify Notepad++ search with regular expression
Result
4
403
200
201
116
15
Example two:
max, dog
lucy, dog
charlie, horse
molly, cat
buddy, cat
daisy, fish
lucky, nina
lucky, sun
Regular Expression
Find: ([a-z]+), ([a-z]+)
Replace: INSERT INTO Users (AccountName, RoleName) Values ('$1', '$2')
4
403
200
201
116
15
Example two:
max, dog
lucy, dog
charlie, horse
molly, cat
buddy, cat
daisy, fish
lucky, nina
lucky, sun
Regular Expression
Find: ([a-z]+), ([a-z]+)
Replace: INSERT INTO Users (AccountName, RoleName) Values ('$1', '$2')
Result
INSERT INTO Users AccountName, RoleName Values 'max', 'dog'
INSERT INTO Users AccountName, RoleName Values 'lucy', 'dog'
INSERT INTO Users AccountName, RoleName Values 'charlie', 'horse'
INSERT INTO Users AccountName, RoleName Values 'molly', 'cat'
INSERT INTO Users AccountName, RoleName Values 'buddy', 'cat'
INSERT INTO Users AccountName, RoleName Values 'daisy', 'fish'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'nina'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'sun'
If you don't know regular expressions, you must change every line of it. If I have over 100.000 rows of it, that may take you many time to do it. So you should learn regular expression for understand the way how to use it!
Exmaple three:
(copyright +(©|\(c\)|©) +\d{4})( *[-,] *\d{4})* and replace with \1-2014 to update all copyright statements to 2014, regardless of the style of copyright symbol and the current copyright year. "copyright (c) 1996-2002
INSERT INTO Users AccountName, RoleName Values 'max', 'dog'
INSERT INTO Users AccountName, RoleName Values 'lucy', 'dog'
INSERT INTO Users AccountName, RoleName Values 'charlie', 'horse'
INSERT INTO Users AccountName, RoleName Values 'molly', 'cat'
INSERT INTO Users AccountName, RoleName Values 'buddy', 'cat'
INSERT INTO Users AccountName, RoleName Values 'daisy', 'fish'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'nina'
INSERT INTO Users AccountName, RoleName Values 'lucky', 'sun'
If you don't know regular expressions, you must change every line of it. If I have over 100.000 rows of it, that may take you many time to do it. So you should learn regular expression for understand the way how to use it!
Exmaple three:
(copyright +(©|\(c\)|©) +\d{4})( *[-,] *\d{4})* and replace with \1-2014 to update all copyright statements to 2014, regardless of the style of copyright symbol and the current copyright year. "copyright (c) 1996-2002
Reference:
The phrase regular expressions (and consequently, regexes) is often used to mean the specific, standard textual syntax (distinct from the mathematical notation described below) for representing patterns that matching text need to conform to. Each character in a regular expression (that is, each character in the string describing its pattern) is understood to be a meta character (with its special meaning), or a regular character (with its literal meaning).
For example, in the regex a. a is a literal character which matches just 'a' and . is a meta character which matches every character except a newline. Therefore, this regex would match for example 'a ' or 'ax' or 'a0'. Together, meta characters and literal characters can be used to identify textual material of a given pattern, or process a number of instances of it.
Pattern-matches can vary from a precise equality to a very general similarity (controlled by the meta characters). For example, . is a very general pattern, [a-z] (match all letters from 'a' to 'z') is less general and a is a precise pattern (match just 'a').
The metacharacter syntax is designed specifically to represent prescribed targets in a concise and flexible way to direct the automation of text processing of a variety of input data, in a form easy to type using a standard ASCII keyboard.
A very simple case of a regular expression in this syntax would be to locate the same word spelled two different ways in a text editor, the regular expression seriali[sz]e matches both "serialise" and "serialize". Wildcards could also achieve this, but are more limited in what they can pattern (having fewer meta characters and a simple language-base).
The usual context of wildcard characters is in globbing similar names in a list of files, whereas regexes are usually employed in applications that pattern-match text strings in general. For example, the regex ^[ \t]+|[ \t]+$ matches excess whitespace at the beginning or end of a line. An advanced regex used to match any numeral is [+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?. See the Examples section for more examples.
For example, in the regex a. a is a literal character which matches just 'a' and . is a meta character which matches every character except a newline. Therefore, this regex would match for example 'a ' or 'ax' or 'a0'. Together, meta characters and literal characters can be used to identify textual material of a given pattern, or process a number of instances of it.
Pattern-matches can vary from a precise equality to a very general similarity (controlled by the meta characters). For example, . is a very general pattern, [a-z] (match all letters from 'a' to 'z') is less general and a is a precise pattern (match just 'a').
The metacharacter syntax is designed specifically to represent prescribed targets in a concise and flexible way to direct the automation of text processing of a variety of input data, in a form easy to type using a standard ASCII keyboard.
A very simple case of a regular expression in this syntax would be to locate the same word spelled two different ways in a text editor, the regular expression seriali[sz]e matches both "serialise" and "serialize". Wildcards could also achieve this, but are more limited in what they can pattern (having fewer meta characters and a simple language-base).
The usual context of wildcard characters is in globbing similar names in a list of files, whereas regexes are usually employed in applications that pattern-match text strings in general. For example, the regex ^[ \t]+|[ \t]+$ matches excess whitespace at the beginning or end of a line. An advanced regex used to match any numeral is [+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?. See the Examples section for more examples.