Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool. NOTE: Asking for HTML, JSON, etc. regexes tends to be met with negative reactions. If there is a parser for it, use that instead.
Regular expressions are a powerful formalism for pattern matching in strings. They are available in a variety of dialects (also known as flavors) in a number of programming languages and text-processing tools, as well as many specialized applications. The term "Regular expression" is typically abbreviated as "RegEx" or "regex".
Further Reading
Learning regular expressions
- Text2Re – Generate Regular expressions based on a string
- Basic concept of how RegularExpression parsing works
- Wikipedia entry on regular expressions
- Regular-Expressions.info (informative website for learning regular expressions)
- RexEgg (a regular expressions tutorial that goes deep into advanced features)
- RegexOne ("learn regular expressions with simple, interactive examples")
- Learn Regex The Hard Way (Online book, new version is in planning phase)
Books
Documentation for JavaScript
Online sandboxes (for testing and publishing regexes online)
- RegexPlanet (supports a variety of flavors to choose from)
- Regexpal (ECMAScript flavor, as implemented by JavaScript)
- Regexhero (.NET flavor)
- RegexStorm.net (.NET flavor with link sharing capability)
- RegExr v2.1 (in JavaScript)
- RegExr v1.0 (ECMAScript flavor, as implemented by Adobe Flash)
- reFiddle (in JavaScript, à la jsFiddle)
- Rubular (Ruby flavor)
- myregexp.com (Java-applet with source code)
- regexe.com (German; probably Java flavor)
- regex101 (in JavaScript, Python, PCRE 16-bit, generates explanation of pattern)
- regexper.com (generates graphical representation for ECMAScript flavor)
- debuggex (generates graphical representation and shows processing of pattern – JavaScript, Python, and PCRE-compatible)
- pyregex.com (Web validator for Python regular expressions)
- regviz.org (Visual debugging of regular expressions for JavaScript)
- Ultrapico Expresso (a standalone tool for testing .NET regular expressions)
- Pythex (Quick way to test your Python regular expressions)
Regex Uses:
Regexps are useful in a wide variety of text processing tasks, and more generally string processing, where the data need not be textual. Common applications include data validation, data scraping (especially web scraping), data wrangling, simple parsing, the production of syntax highlighting systems, and many other tasks.
While regexps would be useful on Internet search engines, processing them across the entire database could consume excessive computer resources depending on the complexity and design of the regex. Although in many cases system administrators can run regex-based queries internally, most search engines do not offer regex support to the public. Notable exceptions: searchcode, or previously Google Code Search, which has been shut down in 2012.
Google also offers re2 (a C++ a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python): it does not backtrack and guarantees linear runtime growth with input size.