From Edutechwiki - Reading time: 3 minRegular expressions (regexps) provide a formalism to identify patterns in some text and any sort of other code. E.g. programmers when creating computer code use to find/replace text in some code, computer program scripts can use regexps to translate code from one form into another (e.g. HTML to Wiki), JavaScript programs may use regexps to check if user data entered in HTML form is correct, etc.
In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
The following examples illustrate a few specifications that could be expressed in a regular expression:
Regular expressions can be much more complex than these examples.
(Wikipedia, retrieved 16:52, 29 August 2008 (UTC)).There exist several definitions / standards / implementations for regeps. They share a common core. The most popular ones are (see the Wikipedia article for details.
Note: Regular expressions (although useful) are difficult to learn and usually only computer programmers use these. However, HTML and XML coders may consider learning some. E.g. if plan to use JavaScript form validation code it's a good thing to know some.
Identifies both img and a begin tags ([http://stackoverflow.com/questions/3790681/regular-expression-to-remove-html-tags StackOverflow)
<(img|a)[^>]*>
Removes span (begin tag)
<span[^>]*>
The following defines a somewhat legal Swiss Zip code:
CH-[0-9]{4,}
The following one defines a valid email address (example from http://www.regular-expressions.info/email.html)
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
Administrators of this wiki can use RegExps to make mass changes to pages.
Example one
The example from the french version below shows how to replace
by
Note how we had to quote the [[ ]]

Example two
Removing pageby + args tag
Search for:
/<pageby nominor="false" comments="false"\/>/
Search for (a bit dangerous):
/<pageby.*\/>/
Replace with:
<!-- -->
Let's assume that you would like to add some line after each <body .....> tag.
Let's find all files that have body tags:
find . -type f -print | xargs grep -l "<body\(.*\)>"
Replace (that's more hairy)
find . -type f -print | xargs perl -i~ -pe "s:<body(.*)>:<body \\1> <p>Something new</p>:g"
Explanations: