词条 | Regular expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
释义 |
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 this pattern is used by string searching algorithms for "find" or "find and replace" operations on strings, or for input validation. It is a technique that 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. PatternsThe 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 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 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 matches excess whitespace at the beginning or end of a line. An advanced regular expression that matches any numeral is . 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 HistoryRegular expressions originated in 1951, when mathematician Stephen Cole Kleene described regular languages using his mathematical notation called regular sets.{{sfn|Kleene|1951}} 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{{sfn|Thompson|1968}} and lexical analysis in a compiler.{{sfn|Johnson|Porter|Ackley|Ross|1968}} 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.{{sfn|Thompson|1968}}[4][5]{{sfn|Aho|Ullman|1992|loc=10.11 Bibliographic Notes for Chapter 10, p. 589}} 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.{{sfn|Aycock|2003|loc=2. JIT Compilation Techniques, 2.1 Genesis, p. 98}} 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: Many variations of these original forms of regular expressions were used in Unix{{sfn|Aho|Ullman|1992|loc=10.11 Bibliographic Notes for Chapter 10, p. 589}} 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.[7] 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.[8] Perl later expanded on Spencer's original library to add many new features,[9] but has not yet caught up with Spencer's Advanced Regular Expressions implementation in terms of performance or Unicode handling.[10][11] 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.[12] 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 conceptsA 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 pattern
A vertical bar separates alternatives. For example, {{code|lang=perl|code=gray{{!}}grey}} can match "gray" or "grey".
Parentheses are used to define the scope and precedence of the operators (among other uses). For example,
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 wildcard 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, The precise syntax for regular expressions varies among tools and with context; more detail is given in the Syntax section. Formal language theoryRegular expressions describe regular languages in formal language theory. They have the same expressive power as regular grammars. Formal definitionRegular 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.[14][15] Given a finite alphabet Σ, the following constants are defined as regular expressions:
Given regular expressions R and S, the following operations over them are defined to produce regular expressions:
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, Many textbooks use the symbols ∪, +, or ∨ for alternation instead of the vertical bar. Examples:
Expressive power and compactnessThe formal definition of regular expressions is purposely parsimonious and avoids defining the redundant quantifiers 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 languages Lk 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 . Generalizing this pattern to Lk gives the expression: 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.[14] 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|date=February 2018}} 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 expressionsAs 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.[18][19] 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.{{clarify|reason=I don't understand the preceding sentence: What is an 'interesting' subset? Does 'perhaps' indicate an open research problem, or what else does it mean? Is it possible to find for each regular expression an equaivalent one built solely from Kleene star and union?|date=February 2015}} 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.[20] Already in 1964, Redko had proved that no finite set of purely equational axioms can characterize the algebra of regular languages.[21] SyntaxA 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 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 DelimitersWhen 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 Standards{{anchor|POSIX}}The IEEE POSIX standard has three sets of compliance: BRE (Basic Regular Expressions),[22] ERE (Extended Regular Expressions), and SRE (Simple Regular Expressions). SRE is deprecated,[23] 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 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, POSIX basic and extendedIn the POSIX standard, Basic Regular Syntax (BRE) requires that the metacharacters
POSIX extendedThe 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,
POSIX Extended Regular Expressions can often be used with modern Unix utilities by including the command line flag -E. Character classesThe 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, could stand for the uppercase alphabet, and could mean any digit. Character classes apply to both POSIX levels. When specifying a range of characters, such as (i.e. lowercase to uppercase ), 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:
POSIX character classes can only be used within bracket expressions. For example, matches the uppercase letters and lowercase "a" and "b". An additional non-POSIX class understood by some tools is , which is usually defined as 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 and ) 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{{see also|Perl Compatible Regular Expressions}}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, 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.[25] Lazy matchingIn Python and some other implementations (e.g. Java), the three common quantifiers ( matches the entire line instead of matching only the first word, However, this does not ensure that not the whole sentence is matched in some contexts. The question-mark operator does not change the meaning of the dot operator, so this still can match the quotes in the input. A pattern like To ensure that the quotes cannot be part of the match, the dot has to be replaced, e. g. like this: Possessive matchingIn 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:[27] While the regex matches the entire line, the regex Possessive quantifiers are easier to implement than greedy and lazy quantifiers, and are typically more efficient at runtime.[27] Patterns for non-regular languagesMany 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 ({{visible anchor|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 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.[28] 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: {{bq|1="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).[12]}}{{anchor|Implementations}}Implementations and running timesThere 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.[29][30] 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 {{code|lang=perl|code=(a{{!}}aa)*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. 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|date=June 2014}} 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. UnicodeIn 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.
UsesRegexes 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.[33] It used a trigram index to speed queries.[34] ExamplesThe 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 web sites 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.[35] metacharacter(s) ;; the metacharacters column specifies the regex syntax being demonstrated =~ m// ;; indicates a regex '''match''' operation in Perl =~ s/// ;; indicates a regex '''substitution''' operation in Perl 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, The syntax and conventions used in these examples coincide with that of other programming environments as well.[36]
Induction{{main|Induction of regular languages}}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
Notes1. ^{{cite web|url=http://www.regular-expressions.info/tutorial.html|title=Regular Expression Tutorial - Learn How to Use Regular Expressions|first=Jan|last=Goyvaerts|website=www.regular-expressions.info}} 2. ^{{cite book|author=Ruslan Mitkov|title=The Oxford Handbook of Computational Linguistics|url=https://books.google.com/books?id=yl6AnaKtVAkC&pg=PA754|year=2003|publisher=Oxford University Press|isbn=978-0-19-927634-9|page=754}} 3. ^{{cite book|author=Mark V. Lawson|title=Finite Automata|url=https://books.google.com/books?id=MDQ_K7-z2AMC&pg=PA98|date=17 September 2003|publisher=CRC Press|isbn=978-1-58488-255-8|pages=98–100}} 4. ^{{cite book | last1 = Kernighan | first1 = Brian | authorlink1 = Brian Kernighan | title = Beautiful Code | chapter = A Regular Expressions Matcher | publisher = O'Reilly Media | pages = 1–2 | chapter-url = http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html | accessdate = 2013-05-15 | isbn = 978-0-596-51004-6| date = 2007-08-08 }} 5. ^{{cite web |url=http://cm.bell-labs.com/who/dmr/qed.html |title=An incomplete history of the QED Text Editor |last1=Ritchie |first1=Dennis M. |publisher= |accessdate=9 October 2013 |archive-url=https://web.archive.org/web/19990221023422/http://cm.bell-labs.com/who/dmr/qed.html |archive-date=1999-02-21 |dead-url=yes |df= }} 6. ^{{cite web | url=http://catb.org/jargon/html/G/grep.html | title=Jargon File 4.4.7: grep | author=Raymond, Eric S. citing Dennis Ritchie | year=2003}} 7. ^{{cite web | url = http://www.tcl.tk/doc/howto/regexp81.html | title = New Regular Expression Features in Tcl 8.1 | accessdate = 2013-10-11}} 8. ^{{cite web | url = http://www.postgresql.org/docs/9.3/interactive/functions-matching.html | title = PostgreSQL 9.3.1 Documentation: 9.7. Pattern Matching | accessdate = 2013-10-12}} 9. ^{{cite web | url=http://perldoc.perl.org/perlre.html | title=perlre: Perl regular expressions | author=Wall, Larry and the Perl 5 development team | year=2006}} 10. ^{{cite web | url= http://perldoc.perl.org/perlreguts.html#Unicode-and-Localisation-Support | title = Unicode and Localisation Support | accessdate = 2013-10-11}} 11. ^{{cite web | url = http://swtch.com/~rsc/regexp/regexp1.html | title = Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, …) | author = Russ Cox | year = 2007 | accessdate = 2013-10-11}} 12. ^1 {{harvtxt|Wall|2002}} 13. ^1 2 grep(1) man page 14. ^1 {{harvtxt|Hopcroft|Motwani|Ullman|2000}} 15. ^{{harvtxt|Sipser|1998}} 16. ^{{harvtxt|Gelade|Neven|2008}} 17. ^{{harvtxt|Gruber|Holzer|2008}} 18. ^{{cite report | url= | author=Jay L. Gischer | institution=Stanford Univ., Dept. of Comp. Sc. | title=(Title unknown) | type=Technical Report | number=STAN-CS-TR-84-1033 | year=1984 }} 19. ^{{cite book | isbn=978-0-201-44124-6 | author=John E. Hopcroft and Rajeev Motwani and Jeffrey D. Ullman | title=Introduction to Automata Theory, Languages, and Computation | location=Upper Saddle River/NJ | publisher=Addison Wesley | year=2003 }} 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. 20. ^{{harvtxt|Kozen|1991}}{{page needed|date=February 2015}} 21. ^{{cite journal| author=V.N. Redko| url=http://umj.imath.kiev.ua/article/?article=10002 | title=On defining relations for the algebra of regular events| journal=Ukrainskii Matematicheskii Zhurnal| year=1964| volume=16| number=1 | pages=120–126}} (In Russian) 22. ^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 23. ^The Single Unix Specification (Version 2) 24. ^1 {{cite web | title = 33.3.1.2 Character Classes — Emacs lisp manual — Version 25.1 | date = 2016 | work = gnu.org | url = https://www.gnu.org/software/emacs/manual/html_node/elisp/Char-Classes.html | access-date = 2017-04-13}} 25. ^{{cite web | url=http://perldoc.perl.org/perlre.html#PCRE%2fPython-Support | title= Perl Regular Expression Documentation |publisher=perldoc.perl.org | accessdate=January 8, 2012}} 26. ^1 {{cite web|title=Regular Expression Syntax|url=https://docs.python.org/3/library/re.html#regular-expression-syntax|website=Python 3.5.0 documentation|publisher=Python Software Foundation|accessdate=10 October 2015}} 27. ^1 {{cite web|title=Essential classes: Regular Expressions: Quantifiers: Differences Among Greedy, Reluctant, and Possessive Quantifiers|url=https://docs.oracle.com/javase/tutorial/essential/regex/quant.html#difs|website=The Java Tutorials|publisher=Oracle|accessdate=23 December 2016}} 28. ^{{cite journal | author=Cezar Câmpeanu and Kai Salomaa, and Sheng Yu | title=A Formal Study of Practical Regular Expressions | journal=International Journal of Foundations of Computer Science | volume=14 | number=6 | pages=1007–1018 | url=http://137.149.157.5/Articles/index.php?aid=1| date=Dec 2003 | doi=10.1142/S012905410300214X }} Theorem 3 (p.9) 29. ^{{harvtxt|Cox|2007}} 30. ^{{harvtxt|Laurikari|2009}} 31. ^{{cite web|url=http://vimdoc.sourceforge.net/htmldoc/pattern.html#/%5B%5D |title=Vim documentation: pattern |publisher=Vimdoc.sourceforge.net |accessdate=2013-09-25}} 32. ^1 {{cite web| title = UTS#18 on Unicode Regular Expressions, Annex A: Character Blocks| url = http://unicode.org/reports/tr18/#Character_Blocks| accessdate = 2010-02-05}} 33. ^{{cite web|last=Google|url=https://googleblog.blogspot.com/2011/10/fall-sweep.html|title=A fall sweep|date=24 October 2011}} 34. ^{{cite web|last=Cox|first=Russ|date=January 2012|url=https://swtch.com/~rsc/regexp/regexp4.html|title=Regular Expression Matching with a Trigram Index, or How Google Code Search Worked}} 35. ^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.36. ^E.g., see Java in a Nutshell, p. 213; Python Scripting for Computational Science, p. 320; Programming PHP, p. 106. 37. ^Note that all the if statements return a TRUE value 38. ^{{cite book | last = Conway | first = Damian | authorlink = Damian Conway | title = Perl Best Practices | chapter = Regular Expressions, End of String | publisher = O'Reilly | pages = 240 | chapter-url = https://www.scribd.com/doc/15491004/Perl-Best-Practices | year=2005 | isbn = 978-0-596-00173-5}} References{{Refbegin|30em}}
| last = Aho | first = Alfred V. | author-link =Alfred Aho | year = 1990 | title = Algorithms for finding patterns in strings | editor-last = van Leeuwen | editor-first = Jan | editor-link = Jan van Leeuwen | work = Handbook of Theoretical Computer Science, volume A: Algorithms and Complexity | publisher = The MIT Press | pages = 255–300 | ref = harv | postscript = }}
| last1 = Aho | first1 = Alfred V. | last2 = Ullman | first2 = Jeffrey D. | authorlink2 = Jeffrey Ullman | year = 1992 | title = Foundations of Computer Science | url = http://infolab.stanford.edu/~ullman/focs.html | chapter = Chapter 10. Patterns, Automata, and Regular Expressions | chapterurl = http://infolab.stanford.edu/~ullman/focs/ch10.pdf | ref = harv }}
| publisher = The Open Group | url = http://pubs.opengroup.org/onlinepubs/007908799/xbd/re.html | title = Regular Expressions | journal = The Single UNIX ® Specification, Version 2 | year = 1997 | ref = harv | postscript = }}
| publisher = The Open Group | url = http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html | title = Chapter 9: Regular Expressions | journal = The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition | year = 2004 | ref = harv | postscript = }}
| url = http://swtch.com/~rsc/regexp/regexp1.html | title = Regular Expression Matching Can Be Simple and Fast | last = Cox | first = Russ | year = 2007 | ref = harv | postscript = }}
| first = Ben | last = Forta | authorlink = Ben Forta | year =2004 | title = Sams Teach Yourself Regular Expressions in 10 Minutes | publisher = Sams | isbn = 978-0-672-32566-3 }}
| first = Jeffrey E. F. | last = Friedl | year =2002 | title = Mastering Regular Expressions | url = http://regex.info/ | publisher = O'Reilly | isbn = 978-0-596-00289-3 }}
| last1 = Gelade | first1 = Wouter | last2 = Neven | first2 = Frank | title = Succinctness of the Complement and Intersection of Regular Expressions | pages = 325–336 | work = Proceedings of the 25th International Symposium on Theoretical Aspects of Computer Science (STACS 2008) | url = http://drops.dagstuhl.de/opus/volltexte/2008/1354 | year = 2008 | ref = harv | postscript = }}
| first = Jan | last = Goyvaerts | first2=Steven |last2=Levithan | year =2009 | title = Regular Expressions Cookbook | publisher = [O'reilly] | isbn = 978-0-596-52068-7 }}
| last1 = Gruber | first1 = Hermann | last2 = Holzer | first2 = Markus | title = Finite Automata, Digraph Connectivity, and Regular Expression Size | pages = 39–50 | work = Proceedings of the 35th International Colloquium on Automata, Languages and Programming (ICALP 2008) | url = http://www.hermann-gruber.com/data/icalp08.pdf | year = 2008 | doi = 10.1007/978-3-540-70583-3_4 | volume = 5126 | ref = harv | postscript = }}
| first = Mehran | last = Habibi | year =2004 | title = Real World Regular Expressions with Java 1.4 | publisher = Springer | isbn = 978-1-59059-107-9 }}
| last1 = Hopcroft | first1 = John E. | last2 = Motwani | first2 = Rajeev | last3 = Ullman | first3 = Jeffrey D. | title = Introduction to Automata Theory, Languages, and Computation | publisher = Addison-Wesley | year = 2000 | edition = 2nd | ref = harv }}
|last = Kleene |first = Stephen C. |title = Representation of Events in Nerve Nets and Finite Automata |work = Automata Studies |editor1-last = Shannon |editor1-first = Claude E. |editor2-last = McCarthy |editor2-first = John |url = https://www.rand.org/content/dam/rand/pubs/research_memoranda/2008/RM704.pdf |publisher = Princeton University Press |year = 1951 |pages = 3–42 |ref = harv |postscript = }}
|last = Kozen |first = Dexter |title = A Completeness Theorem for Kleene Algebras and the Algebra of Regular Events |journal = Proceedings of the 6th Annual IEEE Symposium on Logic in Computer Science (LICS 1991) |pages = 214–225 |year = 1991 |ref = harv |postscript = |hdl = 1813/6963 |doi = 10.1109/LICS.1991.151646 |isbn = 978-0-8186-2230-4
| url=http://www.laurikari.net/tre/ | title = TRE library 0.7.6 | first = Ville | last = Laurikari | year = 2009 | ref = harv }}
| first = François | last = Liger |first2=Craig |last2=McQueen |first3=Paul |last3=Wilton | year =2002 | title = Visual Basic .NET Text Manipulation Handbook | publisher = Wrox Press | isbn = 978-1-86100-730-8 }}
| first = Michael | last = Sipser | authorlink = Michael Sipser | year =1998 | title = Introduction to the Theory of Computation | chapter = Chapter 1: Regular Languages | pages = 31–90 | publisher = PWS Publishing | isbn = 978-0-534-94728-6 | ref = harv }}
| first = Tony | last = Stubblebine | year =2003 | title = Regular Expression Pocket Reference | publisher = O'Reilly | isbn = 978-0-596-00415-6 }}
| url=http://dev.perl.org/perl6/doc/design/apo/A05.html | title=Apocalypse 5: Pattern Matching | first=Larry | last=Wall | authorlink=Larry Wall | year=2002 | ref=harv }}{{Refend}} External links{{wikibooks|Regular Expressions}}{{Wikibooks|1=R Programming |2=Text Processing }}{{Wiktionary|regular expression}}
7 : Automata (computation)|Formal languages|Pattern matching|Programming constructs|Regular expressions|Articles with example code|1951 introductions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。