Java Regex Pattern Matcher Group Example

Working with regular expressions in Java generally involves instantiating a Pattern, and matching it against some text. You can just iterate through the extracted groups in the returned Matcher. // Lets use a regular expression to capture data from a few date strings. String pattern = '([a-zA-Z]+) ( d+)'; Pattern ptrn.

This question already has an answer here:

  • Regex Named Groups in Java 6 answers

I was wondering if Java had an equivalent to C#’s named pattern matching. For example, in C# I can do something like this:

This just seems like a clean way to grab groups. Can Java do something similar, or do I need to grab groups based on index position?

aelstonjonesaelstonjones

marked as duplicate by cricket_007, Tunaki javaFeb 8 '17 at 21:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

This is supported starting in Java 7. Your C# code can be translated to something like this:

Java Regex Pattern Matcher Group Example

You have to create a Matcher object which doesn't actually perform the regex test until you call find().

(I used find() because it can find a match anywhere in the input string, like the Regex.Match() method. The .matches() method only returns true if the regex matches the entire input string.)

mattsmatts

Java v1.7 now supports Perl-standard named groups like (?<name>...) and k<name> in patterns.

You cannot have duplicate group names in the same pattern, which can be annoying in very complex cases where you are building up larger patterns out of smaller pieces out of your control. It also lacks relative indexing.

However, it should be enough for such simple things as you appear to be writing.

tchristtchrist

I believe you need import

org.apache.commons.lang3.StringUtils;

for this

owen gerigowen gerig

Not the answer you're looking for? Browse other questions tagged javaregexmatcher or ask your own question.

The match results of the pattern At least two spaces are matched, but only if they occur directly after a period (.) and before an uppercase letter.
Stephen Cole Kleene, who helped invent the concept
A blacklist on Wikipedia which uses regular expressions to identify bad titles

A regular expression, regex or regexp[1] (sometimes called a rational expression)[2][3] is a sequence of characters that define a search pattern. Usually such patterns are used by string searching algorithms for 'find' or 'find and replace' operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.

The concept arose in the 1950s when the American mathematician Stephen Cole Kleene formalized the description of a regular language. The concept came into common use with Unix text-processing utilities. Since the 1980s, different syntaxes for writing regular expressions exist, one being the POSIX standard and another, widely used, being the Perl syntax.

Regular expressions are used in search engines, search and replace dialogs of word processors and text editors, in text processing utilities such as sed and AWK and in lexical analysis. Many programming languages provide regex capabilities, built-in or via libraries.

  • 4Formal language theory
  • 5Syntax
    • 5.2Standards

Patterns[edit]

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 for matching text. Each character in a regular expression (that is, each character in the string describing its pattern) is either a metacharacter, having a special meaning, or a regular character that has a literal meaning. For example, in the regex a., a is a literal character which matches just 'a', while '.' is a meta character that matches every character except a newline. Therefore, this regex matches, for example, 'a ', or 'ax', or 'a0'. Together, metacharacters and literal characters can be used to identify text of a given pattern, or process a number of instances of it. Pattern matches may vary from a precise equality to a very general similarity, as controlled by the metacharacters. For example, . is a very general pattern, [a-z] (match all lower case letters from 'a' to 'z') is less general and a is a precise pattern (matches 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 ASCIIkeyboard.

A very simple case of a regular expression in this syntax is to locate a word spelled two different ways in a text editor, the regular expression seriali[sz]e matches both 'serialise' and 'serialize'. Wildcards also achieve this, but are more limited in what they can pattern, as they have fewer metacharacters 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 regular expression that matches any numeral is [+-]?(d+(.d+)? .d+)([eE][+-]?d+)?.

Translating the Kleene star
(s* means 'zero or more of s ')

A regex processor translates a regular expression in the above syntax into an internal representation which can be executed and matched against a string representing the text being searched in. One possible approach is the Thompson's construction algorithm to construct a nondeterministic finite automaton (NFA), which is then made deterministic and the resulting deterministic finite automaton (DFA) is run on the target text string to recognize substrings that match the regular expression.The picture shows the NFA scheme N(s*) obtained from the regular expression s*, where s denotes a simpler regular expression in turn, which has already been recursively translated to the NFA N(s).

History[edit]

Regular expressions originated in 1951, when mathematician Stephen Cole Kleene described regular languages using his mathematical notation called regular sets.[4] These arose in theoretical computer science, in the subfields of automata theory (models of computation) and the description and classification of formal languages. Other early implementations of pattern matching include the SNOBOL language, which did not use regular expressions, but instead its own pattern matching constructs.

Regular expressions entered popular use from 1968 in two uses: pattern matching in a text editor[5] and lexical analysis in a compiler.[6] Among the first appearances of regular expressions in program form was when Ken Thompson built Kleene's notation into the editor QED as a means to match patterns in text files.[5][7][8][9] For speed, Thompson implemented regular expression matching by just-in-time compilation (JIT) to IBM 7094 code on the Compatible Time-Sharing System, an important early example of JIT compilation.[10] He later added this capability to the Unix editor ed, which eventually led to the popular search tool grep's use of regular expressions ('grep' is a word derived from the command for regular expression searching in the ed editor: g/re/p meaning 'Global search for Regular Expression and Print matching lines'[11]). Around the same time when Thompson developed QED, a group of researchers including Douglas T. Ross implemented a tool based on regular expressions that is used for lexical analysis in compiler design.[6]

Many variations of these original forms of regular expressions were used in Unix[9] programs at Bell Labs in the 1970s, including vi, lex, sed, AWK, and expr, and in other programs such as Emacs. Regexes were subsequently adopted by a wide range of programs, with these early forms standardized in the POSIX.2 standard in 1992.

In the 1980s the more complicated regexes arose in Perl, which originally derived from a regex library written by Henry Spencer (1986), who later wrote an implementation of Advanced Regular Expressions for Tcl.[12] The Tcl library is a hybrid NFA/DFA implementation with improved performance characteristics. Software projects that have adopted Spencer's Tcl regular expression implementation include PostgreSQL.[13] Perl later expanded on Spencer's original library to add many new features,[14] but has not yet caught up with Spencer's Advanced Regular Expressions implementation in terms of performance or Unicode handling.[15][16] Part of the effort in the design of Perl 6 is to improve Perl's regex integration, and to increase their scope and capabilities to allow the definition of parsing expression grammars.[17] The result is a mini-language called Perl 6 rules, which are used to define Perl 6 grammar as well as provide a tool to programmers in the language. These rules maintain existing features of Perl 5.x regexes, but also allow BNF-style definition of a recursive descent parser via sub-rules.

The use of regexes in structured information standards for document and database modeling started in the 1960s and expanded in the 1980s when industry standards like ISO SGML (precursored by ANSI 'GCA 101-1983') consolidated. The kernel of the structure specification language standards consists of regexes. Its use is evident in the DTD element group syntax.

Starting in 1997, Philip Hazel developed PCRE (Perl Compatible Regular Expressions), which attempts to closely mimic Perl's regex functionality and is used by many modern tools including PHP and Apache HTTP Server.

Today, regexes are widely supported in programming languages, text processing programs (particularly lexers), advanced text editors, and some other programs. Regex support is part of the standard library of many programming languages, including Java and Python, and is built into the syntax of others, including Perl and ECMAScript. Implementations of regex functionality is often called a regex engine, and a number of libraries are available for reuse.

Basic concepts[edit]

A regular expression, often called a pattern, is an expression used to specify a set of strings required for a particular purpose. A simple way to specify a finite set of strings is to list its elements or members. However, there are often more concise ways to specify the desired set of strings. For example, the set containing the three strings 'Handel', 'Händel', and 'Haendel' can be specified by the patternH(ä ae?)ndel; we say that this pattern matches each of the three strings. In most formalisms, if there exists at least one regular expression that matches a particular set then there exists an infinite number of other regular expressions that also match it—the specification is not unique. Most formalisms provide the following operations to construct regular expressions.

Boolean 'or'
A vertical bar separates alternatives. For example, graygrey can match 'gray' or 'grey'.
Grouping
Parentheses are used to define the scope and precedence of the operators (among other uses). For example, gray grey and gr(ae)y are equivalent patterns which both describe the set of 'gray' or 'grey'.
Quantification
A quantifier after a token (such as a character) or group specifies how often that a preceding element is allowed to occur. The most common quantifiers are the question mark?, the asterisk* (derived from the Kleene star), and the plus sign+ (Kleene plus).
?The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both 'color' and 'colour'.
*The asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches 'ac', 'abc', 'abbc', 'abbbc', and so on.
+The plus sign indicates one or more occurrences of the preceding element. For example, ab+c matches 'abc', 'abbc', 'abbbc', and so on, but not 'ac'.
{n}[18]The preceding item is matched exactly n times.
{min,}[18]The preceding item is matched min or more times.
{min,max}[18]The preceding item is matched at least min times, but not more than max times.
Wildcard

The wildcard . matches any character. For example, a.b matches any string that contains an 'a', then any other character and then a 'b', a.*b matches any string that contains an 'a' and a 'b' at some later point.

These constructions can be combined to form arbitrarily complex expressions, much like one can construct arithmetical expressions from numbers and the operations +, , ×, and ÷. For example, H(ae? ä)ndel and H(aaeä)ndel are both valid patterns which match the same strings as the earlier example, H(ä ae?)ndel.

The precise syntax for regular expressions varies among tools and with context; more detail is given in the Syntax section.

Formal language theory[edit]

Regular expressions describe regular languages in formal language theory. They have the same expressive power as regular grammars.

Formal definition[edit]

Regular expressions consist of constants, which denote sets of strings, and operator symbols, which denote operations over these sets. The following definition is standard, and found as such in most textbooks on formal language theory.[19][20] Given a finite alphabet Σ, the following constants are definedas regular expressions:

  • (empty set) ∅ denoting the set ∅.
  • (empty string) ε denoting the set containing only the 'empty' string, which has no characters at all.
  • (literal character) a in Σ denoting the set containing only the character a.

Given regular expressions R and S, the following operations over them are definedto produce regular expressions:

  • (concatenation) RS denotes the set of strings that can be obtained by concatenating a string in R and a string in S. For example, let R = {'ab', 'c'}, and S = {'d', 'ef'}. Then, RS = {'abd', 'abef', 'cd', 'cef'}.
  • (alternation) RS denotes the set union of sets described by R and S. For example, if R describes {'ab', 'c'} and S describes {'ab', 'd', 'ef'}, expression RS describes {'ab', 'c', 'd', 'ef'}.
  • (Kleene star) R* denotes the smallest superset of the set described by R that contains ε and is closed under string concatenation. This is the set of all strings that can be made by concatenating any finite number (including zero) of strings from the set described by R. For example, {'0','1'}* is the set of all finite binary strings (including the empty string), and {'ab', 'c'}* = {ε, 'ab', 'c', 'abab', 'abc', 'cab', 'cc', 'ababab', 'abcab', ... }.

To avoid parentheses it is assumed that the Kleene star has the highest priority, then concatenation and then alternation. If there is no ambiguity then parentheses may be omitted. For example, (ab)c can be written as abc, and a (b(c*)) can be written as a bc*.Many textbooks use the symbols ∪, +, or ∨ for alternation instead of the vertical bar.

Examples:

  • a b* denotes {ε, 'a', 'b', 'bb', 'bbb', ...}
  • (a b)* denotes the set of all strings with no symbols other than 'a' and 'b', including the empty string: {ε, 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', ...}
  • ab*(c ε) denotes the set of strings starting with 'a', then zero or more 'b's and finally optionally a 'c': {'a', 'ac', 'ab', 'abc', 'abb', 'abbc', ...}
  • (0 (1(01*0)*1))* denotes the set of binary numbers that are multiples of 3: { ε, '0', '00', '11', '000', '011', '110', '0000', '0011', '0110', '1001', '1100', '1111', '00000', ... }

Expressive power and compactness[edit]

The formal definition of regular expressions is minimal on purpose, and avoids defining ? and +—these can can be expressed as follows: a+ = aa*, and a? = (a ε). Sometimes the complement operator is added, to give a generalized regular expression; here Rc matches all strings over Σ* that do not match R. In principle, the complement operator is redundant, because it doesn't grant any more expressive power. However, it can make a regular expression much more concise—eliminating all complement operators from a regular expression can cause a double exponentially blow-up of its length.[21][22]

Regular expressions in this sense can express the regular languages, exactly the class of languages accepted by deterministic finite automata. There is, however, a significant difference in compactness. Some classes of regular languages can only be described by deterministic finite automata whose size grows exponentially in the size of the shortest equivalent regular expressions. The standard example here is the languagesLk consisting of all strings over the alphabet {a,b} whose kth-from-last letter equals a. On one hand, a regular expression describing L4 is given by(ab)a(ab)(ab)(ab){displaystyle (amid b)^{*}a(amid b)(amid b)(amid b)}.

Generalizing this pattern to Lk gives the expression:(ab)a(ab)(ab)(ab)k1 times.{displaystyle (amid b)^{*}aunderbrace {(amid b)(amid b)cdots (amid b)} _{k-1{text{ times}}}.,}

On the other hand, it is known that every deterministic finite automaton accepting the language Lk must have at least 2k states. Luckily, there is a simple mapping from regular expressions to the more general nondeterministic finite automata (NFAs) that does not lead to such a blowup in size; for this reason NFAs are often used as alternative representations of regular languages. NFAs are a simple variation of the type-3 grammars of the Chomsky hierarchy.[19]

In the opposite direction, there are many languages easily described by a DFA that are not easily described a regular expression. For instance, determining the validity of a given ISBN requires computing the modulus of the integer base 11, and can be easily implemented with an 11-state DFA. However, a regular expression to answer the same problem of divisibility by 11 is at least multiple megabytes in length.[citation needed]

Given a regular expression, Thompson's construction algorithm computes an equivalent nondeterministic finite automaton. A conversion in the opposite direction is achieved by Kleene's algorithm.

Finally, it is worth noting that many real-world 'regular expression' engines implement features that cannot be described by the regular expressions in the sense of formal language theory; rather, they implement regexes. See below for more on this.

Deciding equivalence of regular expressions[edit]

As seen in many of the examples above, there is more than one way to construct a regular expression to achieve the same results.

It is possible to write an algorithm that, for two given regular expressions, decides whether the described languages are equal; the algorithm reduces each expression to a minimal deterministic finite state machine, and determines whether they are isomorphic (equivalent).

Algebraic laws for regular expressions can be obtained using a method by Gischer which is best explained along an example: In order to check whether (X+Y)* and (X*Y*)* denote the same regular language, for all regular expressions X, Y, it is necessary and sufficient to check whether the particular regular expressions (a+b)* and (a*b*)* denote the same language over the alphabet Σ={a,b}. More generally, an equation E=F between regular-expression terms with variables holds if, and only if, its instantiation with different variables replaced by different symbol constants holds.[23][24]

The redundancy can be eliminated by using Kleene star and set union to find an interesting subset of regular expressions that is still fully expressive, but perhaps their use can be restricted.[clarification needed] This is a surprisingly difficult problem. As simple as the regular expressions are, there is no method to systematically rewrite them to some normal form. The lack of axiom in the past led to the star height problem. In 1991, Dexter Kozen axiomatized regular expressions as a Kleene algebra, using equational and Horn clause axioms.[25]Already in 1964, Redko had proved that no finite set of purely equational axioms can characterize the algebra of regular languages.[26]

Syntax[edit]

A regex pattern matches a target string. The pattern is composed of a sequence of atoms. An atom is a single point within the regex pattern which it tries to match to the target string. The simplest atom is a literal, but grouping parts of the pattern to match an atom will require using ( ) as metacharacters. Metacharacters help form: atoms; quantifiers telling how many atoms (and whether it is a greedy quantifier or not); a logical OR character, which offers a set of alternatives, and a logical NOT character, which negates an atom's existence; and backreferences to refer to previous atoms of a completing pattern of atoms. A match is made, not when all the atoms of the string are matched, but rather when all the pattern atoms in the regex have matched. The idea is to make a small pattern of characters stand for a large number of possible strings, rather than compiling a large list of all the literal possibilities.

Depending on the regex processor there are about fourteen metacharacters, characters that may or may not have their literal character meaning, depending on context, or whether they are 'escaped', i.e. preceded by an escape sequence, in this case, the backslash . Modern and POSIX extended regexes use metacharacters more often than their literal meaning, so to avoid 'backslash-osis' or leaning toothpick syndrome it makes sense to have a metacharacter escape to a literal mode; but starting out, it makes more sense to have the four bracketing metacharacters ( ) and { } be primarily literal, and 'escape' this usual meaning to become metacharacters. Common standards implement both. The usual metacharacters are {}[]()^$. *+? and . The usual characters that become metacharacters when escaped are dswDSW and N.

Delimiters[edit]

When entering a regex in a programming language, they may be represented as a usual string literal, hence usually quoted; this is common in C, Java, and Python for instance, where the regex re is entered as 're'. However, they are often written with slashes as delimiters, as in /re/ for the regex re. This originates in ed, where / is the editor command for searching, and an expression /re/ can be used to specify a range of lines (matching the pattern), which can be combined with other commands on either side, most famously g/re/p as in grep ('global regex print'), which is included in most Unix-based operating systems, such as Linux distributions. A similar convention is used in sed, where search and replace is given by s/re/replacement/ and patterns can be joined with a comma to specify a range of lines as in /re1/,/re2/. This notation is particularly well known due to its use in Perl, where it forms part of the syntax distinct from normal string literals. In some cases, such as sed and Perl, alternative delimiters can be used to avoid collision with contents, and to avoid having to escape occurrences of the delimiter character in the contents. For example, in sed the command s,/,X, will replace a / with an X, using commas as delimiters.

Standards[edit]

The IEEEPOSIX standard has three sets of compliance: BRE (Basic Regular Expressions),[27] ERE (Extended Regular Expressions), and SRE (Simple Regular Expressions). SRE is deprecated,[28] in favor of BRE, as both provide backward compatibility. The subsection below covering the character classes applies to both BRE and ERE.

BRE and ERE work together. ERE adds ?, +, and , and it removes the need to escape the metacharacters ( ) and { }, which are required in BRE. Furthermore, as long as the POSIX standard syntax for regexes is adhered to, there can be, and often is, additional syntax to serve specific (yet POSIX compliant) applications. Although POSIX.2 leaves some implementation specifics undefined, BRE and ERE provide a 'standard' which has since been adopted as the default syntax of many tools, where the choice of BRE or ERE modes is usually a supported option. For example, GNU grep has the following options: 'grep -E' for ERE, and 'grep -G' for BRE (the default), and 'grep -P' for Perl regexes.

Perl regexes have become a de facto standard, having a rich and powerful set of atomic expressions. Perl has no 'basic' or 'extended' levels. As in POSIX EREs, ( ) and { } are treated as metacharacters unless escaped; other metacharacters are known to be literal or symbolic based on context alone. Additional functionality includes lazy matching, backtracking, named capture groups, and recursive patterns.

POSIX basic and extended[edit]

Java regular expression match group example

In the POSIX standard, Basic Regular Syntax (BRE) requires that the metacharacters( ) and { } be designated () and {}, whereas Extended Regular Syntax (ERE) does not.

MetacharacterDescription
^Matches the starting position within the string. In line-based tools, it matches the starting position of any line.
.Matches any single character (many applications exclude newlines, and exactly which characters are considered newlines is flavor-, character-encoding-, and platform-specific, but it is safe to assume that the line feed character is included). Within POSIX bracket expressions, the dot character matches a literal dot. For example, a.c matches 'abc', etc., but [a.c] matches only 'a', '.', or 'c'.
[ ]A bracket expression. Matches a single character that is contained within the brackets. For example, [abc] matches 'a', 'b', or 'c'. [a-z] specifies a range which matches any lowercase letter from 'a' to 'z'. These forms can be mixed: [abcx-z] matches 'a', 'b', 'c', 'x', 'y', or 'z', as does [a-cx-z].

The - character is treated as a literal character if it is the last or the first (after the ^, if present) character within the brackets: [abc-], [-abc]. Note that backslash escapes are not allowed. The ] character can be included in a bracket expression if it is the first (after the ^) character: []abc].

[^ ]Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than 'a', 'b', or 'c'. [^a-z] matches any single character that is not a lowercase letter from 'a' to 'z'. Likewise, literal characters and ranges can be mixed.
$Matches the ending position of the string or the position just before a string-ending newline. In line-based tools, it matches the ending position of any line.
( )Defines a marked subexpression. The string matched within the parentheses can be recalled later (see the next entry, n). A marked subexpression is also called a block or capturing group. BRE mode requires ( ).
nMatches what the nth marked subexpression matched, where n is a digit from 1 to 9. This construct is vaguely defined in the POSIX.2 standard. Some tools allow referencing more than nine capturing groups.
*Matches the preceding element zero or more times. For example, ab*c matches 'ac', 'abc', 'abbbc', etc. [xyz]* matches ', 'x', 'y', 'z', 'zx', 'zyx', 'xyzzy', and so on. (ab)* matches ', 'ab', 'abab', 'ababab', and so on.
{m,n}Matches the preceding element at least m and not more than n times. For example, a{3,5} matches only 'aaa', 'aaaa', and 'aaaaa'. This is not found in a few older instances of regexes. BRE mode requires {m,n}.

Examples:

  • .at matches any three-character string ending with 'at', including 'hat', 'cat', and 'bat'.
  • [hc]at matches 'hat' and 'cat'.
  • [^b]at matches all strings matched by .at except 'bat'.
  • [^hc]at matches all strings matched by .at other than 'hat' and 'cat'.
  • ^[hc]at matches 'hat' and 'cat', but only at the beginning of the string or line.
  • [hc]at$ matches 'hat' and 'cat', but only at the end of the string or line.
  • [.] matches any single character surrounded by '[' and ']' since the brackets are escaped, for example: '[a]' and '[b]'.
  • s.* matches s followed by zero or more characters, for example: 's' and 'saw' and 'seed'.

POSIX extended[edit]

The meaning of metacharacters escaped with a backslash is reversed for some characters in the POSIX Extended Regular Expression (ERE) syntax. With this syntax, a backslash causes the metacharacter to be treated as a literal character. So, for example, ( ) is now ( ) and { } is now { }. Additionally, support is removed for n backreferences and the following metacharacters are added:

MetacharacterDescription
?Matches the preceding element zero or one time. For example, ab?c matches only 'ac' or 'abc'.
+Matches the preceding element one or more times. For example, ab+c matches 'abc', 'abbc', 'abbbc', and so on, but not 'ac'.
The choice (also known as alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc def matches 'abc' or 'def'.

Examples:

  • [hc]?at matches 'at', 'hat', and 'cat'.
  • [hc]*at matches 'at', 'hat', 'cat', 'hhat', 'chat', 'hcat', 'cchchat', and so on.
  • [hc]+at matches 'hat', 'cat', 'hhat', 'chat', 'hcat', 'cchchat', and so on, but not 'at'.
  • cat dog matches 'cat' or 'dog'.

POSIX Extended Regular Expressions can often be used with modern Unix utilities by including the command line flag -E.

Character classes[edit]

The character class is the most basic regex concept after a literal match. It makes one small sequence of characters match a larger set of characters. For example, [A-Z] could stand for the uppercase alphabet, and d could mean any digit. Character classes apply to both POSIX levels.

When specifying a range of characters, such as [a-Z] (i.e. lowercase a to uppercase z), the computer's locale settings determine the contents by the numeric ordering of the character encoding. They could store digits in that sequence, or the ordering could be abc…zABC…Z, or aAbBcC…zZ. So the POSIX standard defines a character class, which will be known by the regex processor installed. Those definitions are in the following table:

POSIXNon-standardPerl/TclVimJavaASCIIDescription
[:ascii:][29]p{ASCII}[x00-x7F]ASCII characters
[:alnum:]p{Alnum}[A-Za-z0-9]Alphanumeric characters
[:word:][29]www[A-Za-z0-9_]Alphanumeric characters plus '_'
WWW[^A-Za-z0-9_]Non-word characters
[:alpha:]ap{Alpha}[A-Za-z]Alphabetic characters
[:blank:]sp{Blank}[ t]Space and tab
b< >b(?<=W)(?=w) (?<=w)(?=W)Word boundaries
B(?<=W)(?=W) (?<=w)(?=w)Non-word boundaries
[:cntrl:]p{Cntrl}[x00-x1Fx7F]Control characters
[:digit:]ddp{Digit} or d[0-9]Digits
DDD[^0-9]Non-digits
[:graph:]p{Graph}[x21-x7E]Visible characters
[:lower:]lp{Lower}[a-z]Lowercase letters
[:print:]pp{Print}[x20-x7E]Visible characters and the space character
[:punct:]p{Punct}[][!'#$%&'()*+,./:;<=>?@^_`{ }~-]Punctuation characters
[:space:]s_sp{Space} or s[ trnvf]Whitespace characters
SSS[^ trnvf]Non-whitespace characters
[:upper:]up{Upper}[A-Z]Uppercase letters
[:xdigit:]xp{XDigit}[A-Fa-f0-9]Hexadecimal digits

POSIX character classes can only be used within bracket expressions. For example, [[:upper:]ab] matches the uppercase letters and lowercase 'a' and 'b'.

An additional non-POSIX class understood by some tools is [:word:], which is usually defined as [:alnum:] plus underscore. This reflects the fact that in many programming languages these are the characters that may be used in identifiers. The editor Vim further distinguishes word and word-head classes (using the notation w and h) since in many programming languages the characters that can begin an identifier are not the same as those that can occur in other positions.

Note that what the POSIX regex standards call character classes are commonly referred to as POSIX character classes in other regex flavors which support them. With most other regex flavors, the term character class is used to describe what POSIX calls bracket expressions.

Perl and PCRE[edit]

Because of its expressive power and (relative) ease of reading, many other utilities and programming languages have adopted syntax similar to Perl's—for example, Java, JavaScript, Julia, Python, Ruby, Qt, Microsoft's .NET Framework, and XML Schema. Some languages and tools such as Boost and PHP support multiple regex flavors. Perl-derivative regex implementations are not identical and usually implement a subset of features found in Perl 5.0, released in 1994. Perl sometimes does incorporate features initially found in other languages, for example, Perl 5.10 implements syntactic extensions originally developed in PCRE and Python.[30]

Lazy matching[edit]

In Python and some other implementations (e.g. Java), the three common quantifiers (*, + and ?) are greedy by default because they match as many characters as possible.[31] The regex '.+' (including the double-quotes) applied to the string

matches the entire line (because the entire line begins and ends with a double-quote) instead of matching only the first part, 'Ganymede,'. The aforementioned quantifiers may, however, be made lazy or minimal or reluctant, matching as few characters as possible, by appending a question mark: '.+?' matches only 'Ganymede,'.[31]

However, the whole sentence can still be matched in some circumstances. The question-mark operator does not change the meaning of the dot operator, so this still can match the double-quotes in the input. A pattern like '.*?' EOF will still match the whole input if this is the string:

To ensure that the double-quotes cannot be part of the match, the dot has to be replaced, e. g. like this: '[^']*' This will match a quoted text part without additional double-quotes in it.

Possessive matching[edit]

In Java, quantifiers may be made possessive by appending a plus sign, which disables backing off, even if doing so would allow the overall match to succeed:[32] While the regex '.*' applied to the string

matches the entire line, the regex '.*+' does not match at all, because .*+ consumes the entire input, including the final '. Thus, possessive quantifiers are most useful with negated character classes, e.g. '[^']*+', which matches 'Ganymede,' when applied to the same string.

Possessive quantifiers are easier to implement than greedy and lazy quantifiers, and are typically more efficient at runtime.[32]

Patterns for non-regular languages[edit]

Many features found in virtually all modern regular expression libraries provide an expressive power that far exceeds the regular languages. For example, many implementations allow grouping subexpressions with parentheses and recalling the value they match in the same expression (backreferences). This means that, among other things, a pattern can match strings of repeated words like 'papa' or 'WikiWiki', called squares in formal language theory. The pattern for these strings is (.+)1.

The language of squares is not regular, nor is it context-free, due to the pumping lemma. However, pattern matching with an unbounded number of backreferences, as supported by numerous modern tools, is still context sensitive.[33]

However, many tools, libraries, and engines that provide such constructions still use the term regular expression for their patterns. This has led to a nomenclature where the term regular expression has different meanings in formal language theory and pattern matching. For this reason, some people have taken to using the term regex, regexp, or simply pattern to describe the latter. Larry Wall, author of the Perl programming language, writes in an essay about the design of Perl 6:

'Regular expressions' […] are only marginally related to real regular expressions. Nevertheless, the term has grown with the capabilities of our pattern matching engines, so I'm not going to try to fight linguistic necessity here. I will, however, generally call them 'regexes' (or 'regexen', when I'm in an Anglo-Saxon mood).[17]

Implementations and running times[edit]

There are at least three different algorithms that decide whether and how a given regex matches a string.

The oldest and fastest relies on a result in formal language theory that allows every nondeterministic finite automaton (NFA) to be transformed into a deterministic finite automaton (DFA). The DFA can be constructed explicitly and then run on the resulting input string one symbol at a time. Constructing the DFA for a regular expression of size m has the time and memory cost of O(2m), but it can be run on a string of size n in time O(n).

An alternative approach is to simulate the NFA directly, essentially building each DFA state on demand and then discarding it at the next step. This keeps the DFA implicit and avoids the exponential construction cost, but running cost rises to O(mn). The explicit approach is called the DFA algorithm and the implicit approach the NFA algorithm. Adding caching to the NFA algorithm is often called the 'lazy DFA' algorithm, or just the DFA algorithm without making a distinction. These algorithms are fast, but using them for recalling grouped subexpressions, lazy quantification, and similar features is tricky.[34][35]

The third algorithm is to match the pattern against the input string by backtracking. This algorithm is commonly called NFA, but this terminology can be confusing. Its running time can be exponential, which simple implementations exhibit when matching against expressions like (aaa)*b that contain both alternation and unbounded quantification and force the algorithm to consider an exponentially increasing number of sub-cases. This behavior can cause a security problem called Regular expression Denial of Service (ReDoS).

Although backtracking implementations only give an exponential guarantee in the worst case, they provide much greater flexibility and expressive power. For example, any implementation which allows the use of backreferences, or implements the various extensions introduced by Perl, must include some kind of backtracking. Some implementations[which?] try to provide the best of both algorithms by first running a fast DFA algorithm, and revert to a potentially slower backtracking algorithm only when a backreference is encountered during the match.

Unicode[edit]

In theoretical terms, any token set can be matched by regular expressions as long as it is pre-defined. In terms of historical implementations, regexes were originally written to use ASCII characters as their token set though regex libraries have supported numerous other character sets. Many modern regex engines offer at least some support for Unicode. In most respects it makes no difference what the character set is, but some issues do arise when extending regexes to support Unicode.

  • Supported encoding. Some regex libraries expect to work on some particular encoding instead of on abstract Unicode characters. Many of these require the UTF-8 encoding, while others might expect UTF-16, or UTF-32. In contrast, Perl and Java are agnostic on encodings, instead operating on decoded characters internally.
  • Supported Unicode range. Many regex engines support only the Basic Multilingual Plane, that is, the characters which can be encoded with only 16 bits. Currently (as of 2016) only a few regex engines (e.g., Perl's and Java's) can handle the full 21-bit Unicode range.
  • Extending ASCII-oriented constructs to Unicode. For example, in ASCII-based implementations, character ranges of the form [x-y] are valid wherever x and y have code points in the range [0x00,0x7F] and codepoint(x) ≤ codepoint(y). The natural extension of such character ranges to Unicode would simply change the requirement that the endpoints lie in [0x00,0x7F] to the requirement that they lie in [0x0000,0x10FFFF]. However, in practice this is often not the case. Some implementations, such as that of gawk, do not allow character ranges to cross Unicode blocks. A range like [0x61,0x7F] is valid since both endpoints fall within the Basic Latin block, as is [0x0530,0x0560] since both endpoints fall within the Armenian block, but a range like [0x0061,0x0532] is invalid since it includes multiple Unicode blocks. Other engines, such as that of the Vim editor, allow block-crossing but the character values must not be more than 256 apart.[36]
  • Case insensitivity. Some case-insensitivity flags affect only the ASCII characters. Other flags affect all characters. Some engines have two different flags, one for ASCII, the other for Unicode. Exactly which characters belong to the POSIX classes also varies.
  • Cousins of case insensitivity. As ASCII has case distinction, case insensitivity became a logical feature in text searching. Unicode introduced alphabetic scripts without case like Devanagari. For these, case sensitivity is not applicable. For scripts like Chinese, another distinction seems logical: between traditional and simplified. In Arabic scripts, insensitivity to initial, medial, final, and isolated position may be desired. In Japanese, insensitivity between hiragana and katakana is sometimes useful.
  • Normalization. Unicode has combining characters. Like old typewriters, plain letters can be followed by one or more non-spacing symbols (usually diacritics like accent marks) to form a single printing character, but also provides precomposed characters, i.e. characters that already include one or more combining characters. A sequence of a character + combining character should be matched with the identical single precomposed character. The process of standardizing sequences of characters + combining characters is called normalization.
  • New control codes. Unicode introduced amongst others, byte order marks and text direction markers. These codes might have to be dealt with in a special way.
  • Introduction of character classes for Unicode blocks, scripts, and numerous other character properties. Block properties are much less useful than script properties, because a block can have code points from several different scripts, and a script can have code points from several different blocks.[37] In Perl and the java.util.regex library, properties of the form p{InX} or p{Block=X} match characters in block X and P{InX} or P{Block=X} matches code points not in that block. Similarly, p{Armenian}, p{IsArmenian}, or p{Script=Armenian} matches any character in the Armenian script. In general, p{X} matches any character with either the binary property X or the general category X. For example, p{Lu}, p{Uppercase_Letter}, or p{GC=Lu} matches any uppercase letter. Binary properties that are not general categories include p{White_Space}, p{Alphabetic}, p{Math}, and p{Dash}. Examples of non-binary properties are p{Bidi_Class=Right_to_Left}, p{Word_Break=A_Letter}, and p{Numeric_Value=10}.

Uses[edit]

Regexes 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 regexes 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: Google Code Search, Exalead. Google Code Search has been shut down as of January 2012.[38]It used a trigram index to speed queries.[39]

Examples[edit]

The specific syntax rules vary depending on the specific implementation, programming language, or library in use. Additionally, the functionality of regex implementations can vary between versions.

Because regexes can be difficult to both explain and understand without examples, interactive websites for testing regexes are a useful resource for learning regexes by experimentation.This section provides a basic description of some of the properties of regexes by way of illustration.

The following conventions are used in the examples.[40]

Also worth noting is that these regexes are all Perl-like syntax. Standard POSIX regular expressions are different.

Unless otherwise indicated, the following examples conform to the Perl programming language, release 5.8.8, January 31, 2006. This means that other implementations may lack support for some parts of the syntax shown here (e.g. basic vs. extended regex, ( ) vs. (), or lack of d instead of POSIX[:digit:]).

The syntax and conventions used in these examples coincide with that of other programming environments as well.[41]

Meta-
character(s)
DescriptionExample[42]
.Normally matches any character except a newline.
Within square brackets the dot is literal.

Output:

( )Groups a series of pattern elements to a single element.
When you match a pattern within parentheses, you can use any of $1, $2, ... later to refer to the previously matched pattern.

Output:

+Matches the preceding pattern element one or more times.

Output:

?Matches the preceding pattern element zero or one time.

Output:

?Modifies the *, +, ? or {M,N}'d regex that comes before to match as few times as possible.

Output:

*Matches the preceding pattern element zero or more times.

Output:

{M,N}Denotes the minimum M and the maximum N match count.
N can be omitted and M can be 0: {M} matches 'exactly' M times; {M,} matches 'at least' M times; {0,N} matches 'at most' N times.
x* y+ z? is thus equivalent to x{0,} y{1,} z{0,1}.

Output:

[…]Denotes a set of possible character matches.

Output:

Separates alternate possibilities.

Output:

bMatches a zero-width boundary between a word-class character (see next) and either a non-word class character or an edge; same as

(^w w$ Ww wW).

Output:

wMatches an alphanumeric character, including '_';
same as [A-Za-z0-9_] in ASCII, and
[p{Alphabetic}p{GC=Mark}p{GC=Decimal_Number}p{GC=Connector_Punctuation}]

in Unicode,[37] where the Alphabetic property contains more than Latin letters, and the Decimal_Number property contains more than Arab digits.

Output:

WMatches a non-alphanumeric character, excluding '_';
same as [^A-Za-z0-9_] in ASCII, and
[^p{Alphabetic}p{GC=Mark}p{GC=Decimal_Number}p{GC=Connector_Punctuation}]

in Unicode.

Output:

sMatches a whitespace character,
which in ASCII are tab, line feed, form feed, carriage return, and space;
in Unicode, also matches no-break spaces, next line, and the variable-width spaces (amongst others).

Output:

SMatches anything BUT a whitespace.

Output:

dMatches a digit;
same as [0-9] in ASCII;
in Unicode, same as the p{Digit} or p{GC=Decimal_Number} property, which itself the same as the p{Numeric_Type=Decimal} property.

Output:

DMatches a non-digit;
same as [^0-9] in ASCII or P{Digit} in Unicode.

Output:

^Matches the beginning of a line or string.

Output:

$Matches the end of a line or string.

Output:

AMatches the beginning of a string (but not an internal line).

Output:

zMatches the end of a string (but not an internal line).[43]

Output:

[^…]Matches every character except the ones inside brackets.

Output:

Java regex match group example

Java Regular Expression Match Group Example

Induction[edit]

Regular expressions can often be created ('induced' or 'learned') based on a set of example strings. This is known as the induction of regular languages, and is part of the general problem of grammar induction in computational learning theory. Formally, given examples of strings in a regular language, and perhaps also given examples of strings not in that regular language, it is possible to induce a grammar for the language, i.e., a regular expression that generates that language. Not all regular languages can be induced in this way (see language identification in the limit), but many can. For example, the set of examples {1, 10, 100}, and negative set (of counterexamples) {11, 1001, 101, 0} can be used to induce the regular expression 1⋅0* (1 followed by zero or more 0s).

See also[edit]

  • Thompson's construction algorithm – converts a regular expression into an equivalent nondeterministic finite automaton (NFA)

Notes[edit]

  1. ^Goyvaerts, Jan. 'Regular Expression Tutorial - Learn How to Use Regular Expressions'. www.regular-expressions.info.
  2. ^Ruslan Mitkov (2003). The Oxford Handbook of Computational Linguistics. Oxford University Press. p. 754. ISBN978-0-19-927634-9.
  3. ^Mark V. Lawson (17 September 2003). Finite Automata. CRC Press. pp. 98–100. ISBN978-1-58488-255-8.
  4. ^Kleene 1951.
  5. ^ abThompson 1968.
  6. ^ abJohnson et al. 1968.
  7. ^Kernighan, Brian (2007-08-08). 'A Regular Expressions Matcher'. Beautiful Code. O'Reilly Media. pp. 1–2. ISBN978-0-596-51004-6. Retrieved 2013-05-15.
  8. ^Ritchie, Dennis M. 'An incomplete history of the QED Text Editor'. Archived from the original on 1999-02-21. Retrieved 9 October 2013.
  9. ^ abAho & Ullman 1992, 10.11 Bibliographic Notes for Chapter 10, p. 589.
  10. ^Aycock 2003, 2. JIT Compilation Techniques, 2.1 Genesis, p. 98.
  11. ^Raymond, Eric S. citing Dennis Ritchie (2003). 'Jargon File 4.4.7: grep'.
  12. ^'New Regular Expression Features in Tcl 8.1'. Retrieved 2013-10-11.
  13. ^'PostgreSQL 9.3.1 Documentation: 9.7. Pattern Matching'. Retrieved 2013-10-12.
  14. ^Wall, Larry and the Perl 5 development team (2006). 'perlre: Perl regular expressions'.
  15. ^'Unicode and Localisation Support'. Retrieved 2013-10-11.
  16. ^Russ Cox (2007). 'Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, …)'. Retrieved 2013-10-11.
  17. ^ abWall (2002)
  18. ^ abcgrep(1) man page
  19. ^ abHopcroft, Motwani & Ullman (2000)
  20. ^Sipser (1998)
  21. ^Gelade & Neven (2008)
  22. ^Gruber & Holzer (2008)
  23. ^Jay L. Gischer (1984). (Title unknown) (Technical Report). Stanford Univ., Dept. of Comp. Sc.
  24. ^John E. Hopcroft and Rajeev Motwani and Jeffrey D. Ullman (2003). Introduction to Automata Theory, Languages, and Computation. Upper Saddle River/NJ: Addison Wesley. ISBN978-0-201-44124-6. Here: Sect.3.4.6, p.117-120. — This property need not hold for extended regular expressions, even if they describe no larger class than regular languages; cf. p.121.
  25. ^Kozen (1991)[page needed]
  26. ^V.N. Redko (1964). 'On defining relations for the algebra of regular events'. Ukrainskii Matematicheskii Zhurnal. 16 (1): 120–126. (In Russian)
  27. ^ISO/IEC 9945-2:1993 Information technology – Portable Operating System Interface (POSIX) – Part 2: Shell and Utilities, successively revised as ISO/IEC 9945-2:2002 Information technology – Portable Operating System Interface (POSIX) – Part 2: System Interfaces, ISO/IEC 9945-2:2003, and currently ISO/IEC/IEEE 9945:2009 Information technology – Portable Operating System Interface (POSIX®) Base Specifications, Issue 7
  28. ^The Single Unix Specification (Version 2)
  29. ^ ab'33.3.1.2 Character Classes — Emacs lisp manual — Version 25.1'. gnu.org. 2016. Retrieved 2017-04-13.
  30. ^'Perl Regular Expression Documentation'. perldoc.perl.org. Retrieved January 8, 2012.
  31. ^ ab'Regular Expression Syntax'. Python 3.5.0 documentation. Python Software Foundation. Retrieved 10 October 2015.
  32. ^ ab'Essential classes: Regular Expressions: Quantifiers: Differences Among Greedy, Reluctant, and Possessive Quantifiers'. The Java Tutorials. Oracle. Retrieved 23 December 2016.
  33. ^Cezar Câmpeanu and Kai Salomaa, and Sheng Yu (Dec 2003). 'A Formal Study of Practical Regular Expressions'. International Journal of Foundations of Computer Science. 14 (6): 1007–1018. doi:10.1142/S012905410300214X. Theorem 3 (p.9)
  34. ^Cox (2007)
  35. ^Laurikari (2009)
  36. ^'Vim documentation: pattern'. Vimdoc.sourceforge.net. Retrieved 2013-09-25.
  37. ^ ab'UTS#18 on Unicode Regular Expressions, Annex A: Character Blocks'. Retrieved 2010-02-05.
  38. ^Horowitz, Bradley (24 October 2011). 'A fall sweep'. Google Blog. Retrieved 4 May 2019.
  39. ^Cox, Russ (January 2012). 'Regular Expression Matching with a Trigram Index, or How Google Code Search Worked'. swtch.com. Retrieved 4 May 2019.
  40. ^The character 'm' is not always required to specify a Perl match operation. For example, m/[^abc]/ could also be rendered as /[^abc]/. The 'm' is only necessary if the user wishes to specify a match operation without using a forward-slash as the regex delimiter. Sometimes it is useful to specify an alternate regex delimiter in order to avoid 'delimiter collision'. See 'perldoc perlre' for more details.
  41. ^E.g., see , p. 213; Python Scripting for Computational Science, p. 320; Programming PHP, p. 106.
  42. ^Note that all the if statements return a TRUE value
  43. ^Conway, Damian (2005). 'Regular Expressions, End of String'. Perl Best Practices. O'Reilly. p. 240. ISBN978-0-596-00173-5.

References[edit]

  • Aho, Alfred V. (1990). van Leeuwen, Jan (ed.). Algorithms for finding patterns in strings. Handbook of Theoretical Computer Science, volume A: Algorithms and Complexity. The MIT Press. pp. 255–300.
  • Aho, Alfred V.; Ullman, Jeffrey D. (1992). 'Chapter 10. Patterns, Automata, and Regular Expressions'(PDF). Foundations of Computer Science.
  • 'Regular Expressions'. The Single UNIX ® Specification, Version 2. The Open Group. 1997.
  • 'Chapter 9: Regular Expressions'. The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition. The Open Group. 2004.
  • Cox, Russ (2007). 'Regular Expression Matching Can Be Simple and Fast'.
  • Forta, Ben (2004). Sams Teach Yourself Regular Expressions in 10 Minutes. Sams. ISBN978-0-672-32566-3.
  • Friedl, Jeffrey E. F. (2002). Mastering Regular Expressions. O'Reilly. ISBN978-0-596-00289-3.
  • Gelade, Wouter; Neven, Frank (2008). Succinctness of the Complement and Intersection of Regular Expressions. Proceedings of the 25th International Symposium on Theoretical Aspects of Computer Science (STACS 2008). pp. 325–336.
  • Goyvaerts, Jan; Levithan, Steven (2009). Regular Expressions Cookbook. [O'reilly]. ISBN978-0-596-52068-7.
  • Gruber, Hermann; Holzer, Markus (2008). Finite Automata, Digraph Connectivity, and Regular Expression Size(PDF). Proceedings of the 35th International Colloquium on Automata, Languages and Programming (ICALP 2008). 5126. pp. 39–50. doi:10.1007/978-3-540-70583-3_4.
  • Habibi, Mehran (2004). Real World Regular Expressions with Java 1.4. Springer. ISBN978-1-59059-107-9.
  • Hopcroft, John E.; Motwani, Rajeev; Ullman, Jeffrey D. (2000). Introduction to Automata Theory, Languages, and Computation (2nd ed.). Addison-Wesley.
  • Johnson, Walter L.; Porter, James H.; Ackley, Stephanie I.; Ross, Douglas T. (1968). 'Automatic generation of efficient lexical processors using finite state techniques'. Communications of the ACM. 11 (12): 805–813. doi:10.1145/364175.364185.
  • Kleene, Stephen C. (1951). Shannon, Claude E.; McCarthy, John (eds.). Representation of Events in Nerve Nets and Finite Automata(PDF). Automata Studies. Princeton University Press. pp. 3–42.
  • Kozen, Dexter (1991). A Completeness Theorem for Kleene Algebras and the Algebra of Regular Events. Proceedings of the 6th Annual IEEE Symposium on Logic in Computer Science (LICS 1991). pp. 214–225. doi:10.1109/LICS.1991.151646. hdl:1813/6963. ISBN978-0-8186-2230-4.
  • Laurikari, Ville (2009). 'TRE library 0.7.6'.
  • Liger, François; McQueen, Craig; Wilton, Paul (2002). Visual Basic .NET Text Manipulation Handbook. Wrox Press. ISBN978-1-86100-730-8.
  • Sipser, Michael (1998). 'Chapter 1: Regular Languages'. Introduction to the Theory of Computation. PWS Publishing. pp. 31–90. ISBN978-0-534-94728-6.
  • Stubblebine, Tony (2003). Regular Expression Pocket Reference. O'Reilly. ISBN978-0-596-00415-6.
  • Thompson, Ken (1968). 'Programming Techniques: Regular expression search algorithm'. Communications of the ACM. 11 (6): 419–422. doi:10.1145/363347.363387.
  • Wall, Larry (2002). 'Apocalypse 5: Pattern Matching'.

External links[edit]

Java Regex Pattern Matcher Group Example

Wikibooks has a book on the topic of: Regular Expressions
The Wikibook R Programming has a page on the topic of: Text Processing

Java Regex Matcher Group Example

Look up regular expression in Wiktionary, the free dictionary.
  • Media related to Regex at Wikimedia Commons
  • Regular Expressions at Curlie
  • ISO/IEC 9945-2:1993 Information technology – Portable Operating System Interface (POSIX) – Part 2: Shell and Utilities
  • ISO/IEC 9945-2:2002 Information technology – Portable Operating System Interface (POSIX) – Part 2: System Interfaces
  • ISO/IEC 9945-2:2003 Information technology – Portable Operating System Interface (POSIX) – Part 2: System Interfaces
  • ISO/IEC/IEEE 9945:2009 Information technology – Portable Operating System Interface (POSIX®) Base Specifications, Issue 7
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Regular_expression&oldid=899032179'