Regular Expression - meaning of word
Rozmiar: 8938 bajtów


Regular Expression



#REDIRECT Regular expression

Regular expression



A regular expression (abbreviated as regexp, regex, or regxp, with plural forms regexps, regexes, or regexen) is a string (computer science) that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns. Many programming languages support regular expressions for string manipulation. For example, Perl has a powerful regular expression engine built directly into its syntax. The set of utilities (including the editor sed and the filter grep) provided by Unix distributions were the first to popularize the concept of regular expressions. ==Basic concepts== A regular expression, often called a ''pattern'', is an expression that describes a set of strings without actually listing its elements. For example, the three strings ''Handel'', ''Händel'', and ''Haendel'' are described by the pattern "H(ä|ae?)ndel". Most formalisms provide the following constructions, which are introduced here by example. ;alternation :A vertical bar separates alternatives. For example, "gray|grey" matches ''grey'' or ''gray''. ;quantification :A quantifier after a character specifies how often that character is allowed to occur. The most common quantifiers are +, ?, and *: :;+ ::The plus sign indicates that the preceding character must be present at least once. For example, "goo+gle" matches the infinite set ''google'', ''gooogle'', ''goooogle'', etc. (but not ''gogle''). :;? ::The question mark indicates that the preceding character may be present at most once. For example, "colou?r" matches ''color'' and ''colour''. :;* ::The asterisk indicates that the preceding character may be present zero, one, or more times. For example, "0*42" matches ''42'', ''042'', ''0042'', etc. ;grouping :Parentheses are used to define the scope and precedence of the other operators. For example, "gr(a|e)y" is the same as "gray|grey", and "(grand)?father" matches both ''father'' and ''grandfather''. The constructions can be freely combined within the same expression, so that "H(ae?|ä)ndel" is the same as "H(a|ae|ä)ndel". The precise syntax for regular expressions varies among tools and application areas, and is described in more detail below. ==History== The origin of regular expressions lies in automata theory and formal language theory (both part of theoretical computer science). These fields study models of computation (automata) and ways to describe and classify formal languages. In the 1940s, Warren McCulloch and Walter Pitts described the nervous system by modelling neurons as small simple automata. The mathematician Stephen Kleene later described these models using his mathematical notation called ''regular sets''. Ken Thompson built this notation into the editor QED (text editor), then into the Unix editor ed and eventually into grep. Ever since that time, regular expressions have been widely used in Unix and Unix-like utilities such as: expr, awk, Emacs, vi, lex, and Perl. Perl regular expressions were derived from regex written by Henry Spencer. Philip Hazel developed [http://www.pcre.org/ pcre] (Perl Compatible Regular Expressions) which attempts to closely mimic Perl's regular expression functionality, and is used by many modern tools such as Python programming language, PHP, and Apache HTTP Server. The integration of regular expressions in most computer languages is still very poor and, even though Perl's regular expression integration is one of the best around, part of the effort in the design of the future [http://dev.perl.org/perl6 Perl6] is improving this integration. This is the subject of [http://dev.perl.org/perl6/apocalypse/A05.html Apocalypse 5]. ==In formal language theory== Regular expressions consist of constants and operators that denote sets of strings and operations over these sets, respectively. Given a finite alphabet Σ the following constants are defined: * (''empty set'') ∅ denoting the set ∅ * (''empty string'') ε denoting the set {ε} * (''Literal string'') ''a'' in Σ denoting the set {''a''} and the following operations: * (''concatenation'') ''RS'' denoting the set { αβ | α in ''R'' and β in ''S'' }. For example {"ab", "c"}{"d", "ef"} = {"abd", "abef", "cd", "cef"}. * (''alternation'') ''R|S'' denoting the set union of ''R'' and ''S''. * (''Kleene star'') ''R''* denoting the smallest superset of ''R'' that contains ε and is closed under string concatenation. This is the set of all strings that can be made by concatenating zero or more strings in ''R''. For example, {"ab", "c"}* = {ε, "ab", "c", "abab", "abc", "cab", "cc", "ababab", ... }. Many textbooks use the symbols ∪, +, or ∨ for alternation instead of the vertical bar. To avoid brackets it is assumed that the Kleene star has the highest priority, then concatenation and then set union. If there is no ambiguity then brackets may be omitted. For example, (ab)c is written as abc and a|(b(c*)) can be written as a|bc*. Examples: * a|b* denotes {ε, ''a'', ''b'', ''bb'', ''bbb'', ...} * (a|b)* denotes the set of all strings consisting of any number of ''a'' and ''b'' symbols, including the empty string * b*(ab*)* the same * ab*(c|ε) denotes the set of strings starting with ''a'', then zero or more ''b''s and finally optionally a ''c''. * ((a|ba(aa)*b)(b(aa)*b)*(a|ba(aa)*b)|b(aa)*b)*(a|ba(aa)*b)(b(aa)*b)* denotes the set of all strings which contain an even number of ''b''s and an odd number of ''a''s. Note that this regular expression is of the form (''X'' ''Y''*''X'' U ''Y'')*''X'' ''Y''* with ''X'' = a|ba(aa)*b and ''Y'' = b(aa)*b. The formal definition of regular expressions is purposefully parsimonious and avoids defining the redundant quantifiers ? and +, which can be expressed as follows: ''a''+= aa*, and ''a''? = (ε|a). Sometimes the complement operator ~ is added; ~''R'' denotes the set of all strings over Σ that are not in ''R''. In that case the resulting operators form a Kleene algebra. The complement operator is redundant: it can always be expressed by only using the other operators. Regular expressions in this sense can express exactly the class of languages accepted by finite state automaton: the regular languages. There is, however, a significant difference in compactness: some classes of regular languages can only be described by automata that exponential growth in size, while the required regular expressions only grow linearly. Regular expressions correspond to the type 3 formal grammar of the Chomsky hierarchy and may be used to describe a regular language. We can also study expressive power within the formalism. As the example shows, different regular expressions can express the same language: the formalism is redundant. It is possible to write an algorithm which for two given regular expressions decides whether the described languages are equal - essentially, it reduces each expression to a minimal deterministic finite state automaton and determines whether they are isomorphic (equivalent). To what extent can this redundancy be eliminated? Can we find an interesting subset of regular expressions that is still fully expressive? Kleene star and set union are obviously required, but perhaps we can restrict their use. This turns out to be a surprisingly difficult problem. As simple as the regular expressions are, it turns out there is no method to systematically rewrite them to some normal form. They are not finitely axiomatizable. So we have to resort to other methods. This leads to the star height problem. It is worth noting that many real-world "regular expression" engines implement features that cannot be expressed in the regular expression algebra; see #Patterns for irregular languages for more on this. ==Syntaxes== ===Traditional Unix regular expressions=== The "basic" Unix regular expression syntax is now defined as obsolete by POSIX, but is still widely used for the purposes of backwards compatibility. Most regular-expression–aware Unix utilities, for example ''grep'' and ''sed'', use it by default. In this syntax, most characters are treated as literals—they match only themselves ("a" matches "a", "(bc" matches "(bc", etc). The exceptions are called metacharacters: {| valign="top" |. |Matches any single character |- valign="top" |[ ] |Matches a single character that is contained within the brackets. For example, [abc] matches "a", "b", or "c". [a-z] matches any lowercase letter. These can be mixed: [abcq-z] matches a, b, c, q, r, s, t, u, v, w, x, y, z, and so does [a-cq-z]. The '-' character should be literal only if it is the last or the first character within the brackets: [abc-] or [-abc]. To match an '[' or ']' character, the easiest way is to make sure the closing bracket is first in the enclosing square brackets: [][ab] matches ']', '[', 'a' or 'b'. |- valign="top" |[^ ] |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. As above, these can be mixed. |- valign="top" |^ |Matches the start of the line (or any line, when applied in multiline mode) |- valign="top" |$ |Matches the end of the line (or any line, when applied in multiline mode) |- valign="top" |\( \) |Define a "marked subexpression". What the enclosed expression matched can be recalled later. See the next entry, \''n''. Note that a "marked subexpression" is also a "block" |- valign="top" |\''n'' |Where ''n'' is a digit from 1 to 9; matches what the ''n''th marked subexpression matched. This construct is theoretically irregular and has not been adopted in the extended regular expression syntax. |- valign="top" |* | *A single character expression followed by "*" matches zero or more copies of the expression. For example, "[xyz]*" matches "", "x", "y", "zx", "zyx", and so on. *\''n''*, where ''n'' is a digit from 1 to 9, matches zero or more iterations of what the ''n''th marked subexpression matched. For example, "\(a?\)c\1*" matches "abcab" and "abcaba" but not "abcac". *An expression enclosed in "\(" and "\)" followed by "*" is deemed to be invalid. In some cases (e.g. /usr/bin/xpg4/grep of SunOS 5.8), it matches zero or more iterations of the string that the enclosed expression matches. In other cases (e.g. /usr/bin/grep of SunOS 5.8), it matches what the enclosed expression matches, followed by a literal "*". |- valign="top" |\{''x'',''y''\} |Match the last "block" at least ''x'' and not more than ''y'' times. For example, "a\{3,5\}" matches "aaa", "aaaa" or "aaaaa". Note that this is not found in some instances of regex. |} Old versions of ''grep'' did not support the alternation operator "|". Examples: : ".at" matches any three-character string ending with ''at'' : "[hc]at" matches ''hat'' and ''cat'' : "[^b]at" matches any three-character string ending with ''at'' and not beginning with ''b''. : "^[hc]at" matches ''hat'' and ''cat'' but only at the beginning of a line : "[hc]at$" matches ''hat'' and ''cat'' but only at the end of a line Since many ranges of characters depends on the chosen locale setting (e.g., in some settings letters are organized as abc..yzABC..YZ while in some others as aAbBcC..yYzZ) the POSIX standard defines some classes or categories of characters as shown in the following table: {| |- align="left" ! POSIX class !! similar to !! meaning |- | [:upper:] | [A-Z] | uppercase letters |- | [:lower:] | [a-z] | lowercase letters |- | [:alpha:] | [A-Za-z] | upper- and lowercase letters |- | [:alnum:] | [A-Za-z0-9] | digits, upper- and lowercase letters |- | [:digit:] | [0-9] | digits |- | [:xdigit:] | [0-9A-Fa-f] | hexadecimal digits |- | [:punct:] | [.,!?:...] | punctuation |- | [:blank:] | [ \t] | space and TAB |- | [:space:] | [ \t\n\r\f\v] | blank characters |- | [:cntrl:] | | control characters |- | [:graph:] | [^ \t\n\r\f\v] | printed characters |- | [:print:] | [^\t\n\r\f\v] | printed characters and space |} example: [[:upper:]ab] should only return the upper letters and 'a' 'b' lower. ===POSIX modern (extended) regular expressions=== The more modern "extended" regular expressions can often be used with modern Unix utilities by including the command line flag "-E". POSIX extended regular expressions are similar in syntax to the traditional Unix regular expressions, with some exceptions. The following metacharacters are added:
+ Match the last "block" one or more times - "ba+" matches "ba", "baa", "baaa" and so on
? Match the last "block" zero or one times - "ba?" matches "b" or "ba"
| The choice (or set union) operator: match either the expression before or the expression after the operator - "abc|def" matches "abc" or "def".
Also, backslashes are removed: \{...\} becomes {...} and \(...\) becomes (...) Examples: : "[hc]+at" matches with "hat", "cat", "hhat", "chat", "hcat", "ccchat" et cetera : "[hc]?at" matches "hat", "cat" and "at" : "([cC]at)|([dD]og)" matches "cat", "Cat", "dog" and "Dog" Since the characters '(', ')', '[', ']', '.', '*', '?', '+', '^' and '$' are used as special symbols they have to be "escaped" somehow if they are meant literally. This is done by preceding them with '\' which therefore also has to be "escaped" this way if meant literally. Examples: : ".\.(\(|\))" matches with the string "a.)" ===Perl-compatible regular expressions (PCRE)=== Perl has a much richer syntax than even the extended POSIX regexp. In addition, its syntax is somewhat more predictable (for example, a backstroke always quotes a non-alphanumeric character). For these reasons, the Perl syntax has been adopted in other utilities and applications -- Tcl and exim, for example. ===Patterns for irregular languages=== Many patterns provide an expressive power that far exceeds the regular languages. For example, the ability to group subexpressions with brackets and recall them in the same expression means that a pattern can match strings of repeated words like "papa" or "WikiWiki", called ''squares'' in formal language theory. The pattern for these strings is just "(.*)\1". However, the language of squares is not regular, nor is it context-free. Pattern matching with an unbounded number of back references, as supported by a number of modern tools, is NP-complete. However, many tools, libraries, and engines that provide such constructions still use the term ''regular expression'' for their patterns. This has lead to a nomenclature where the term "regular expression" has different meanings in formal language theory and pattern matching. It has been suggested to use the term ''regex'' or simply "pattern" for the latter. Larry Wall (author of Perl) writes in Apocalypse 5: :"[R]egular 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). ===Implementations and running times=== There are at least two different algorithms that decide if (and how) a given string matches a regular expression. The oldest and fastest relies on a result in formal language theory that allows every Nondeterministic Finite State Machine (NFA) to be transformed into a deterministic finite state machine (DFA). The algorithm performs or simulates this transformation and then runs the resulting DFA on the input string, one symbol at a time. The latter process takes time linear in the length of the input string. More precisely, an input string of size ''n'' can be tested against a regular expression of size ''m'' in time ''O''(''n+2m'') or ''O''(''nm''), depending on the details of the implementation. This algorithm is often referred to as DFA. It is fast, but can be used only for matching and not for recalling grouped subexpressions. The other algorithm is to match the pattern against the input string by backtracking. (This algorithm is sometimes called NFA, but this terminology is highly confusing.) Its running time can be exponential, which many implementations exhibit when matching against expressions like "(a|aa)*b" that contain both alternation and unbounded quantification and force the algorithm to consider an exponential number of subcases. Even though backtracking implementations give no running time guarantee in the worst case, they allow much greater flexibility and provide more expressive power. Some implementations try to provide the best of both algorithms by first running a fast DFA match to see if the string matches the regular expression at all, and only in that case perform a potentially slower backtracking match. ==See also== *Perl_regular_expression_examples *wildmat ==References== *Jeffrey Friedl: ''[http://regex.info/ Mastering Regular Expressions]'', O'Reilly Media, ISBN 0-596-00289-0 *Tony Stubblebine: ''Regular Expression'', Pocket Reference, O'Reilly, ISBN 0-596-00415-X *Ben Forta: ''Sams Teach Yourself Regular Expressions in 10 Minutes'', Sams, ISBN 0-672-32566-7 *Mehran Habibi: ''Real World Regular Expressions with Java 1.4'', Springer, ISBN 1-59059-107-0 *Francois Liger, Craig McQueen, Paul Wilton: ''Visual Basic .NET Text Manipulation Handbook'', Wrox Press, ISBN 1-86100-730-2 *Michael Sipser: ''Introduction to the Theory of Computation'', PWS Publishing Company, ISBN 0-534-94728-X ==External links== *[http://www.regexlib.com/ Regular Expression Library] Currently we have indexed 926 expressions from contributors around the world. *[http://dmoz.org/Computers/Programming/Languages/Regular_Expressions/ DMOZ listing] * Articles/Archives: **[http://www.greenend.org.uk/rjk/2002/06/regexp.html Regexp Syntax Summary], reference table for different styles of regular expressions **[http://RegExLib.com/ online regular expression archive] **[http://www.regular-expressions.info Regular expression information] **[http://www.xrce.xerox.com/competencies/content-analysis/fsCompiler/fssyntax.html ''Syntax and Semantics of Regular Expressions''] by Xerox Research Centre Europe **[http://gnosis.cx/publish/programming/regular_expressions.html Learning to Use Regular Expressions] by David Mertz **[http://www.regex.info/ ''Mastering Regular Expressions'' book website] **[http://www.regenechsen.de/regex_en/regex_1_en.html Regenechsen], Beginners tutorial for using Regular Expressions **[http://cm.bell-labs.com/cm/cs/who/dmr/qed.html An incomplete history of the QED text editor] **[http://boost-sandbox.sourceforge.net/libs/xpressive/doc/html/index.html xpressive] **[http://research.microsoft.com/projects/greta/ The GRETA Regular Expression Template Archive] * Tools: **[http://www.miningtools.net/regextester.aspx Regular expression .NET online tester] **[http://weitz.de/regex-coach/ The Regex Coach], a very powerful interactive learning system to hone your regexp skills **[http://txt2regex.sourceforge.net/ ^txt2regex$], a Regular Expression Wizard that converts human sentences to regexps **[http://renschler.net/RegexBuilder/ RegexBuilder], Simple .NET tool to test regular expressions **[http://www.doulos.com/knowhow/tcltk/examples/trev/ Tcl Regular Expression Visualiser] **[http://jregexptester.sourceforge.net/ JRegexpTester], free java regexp testing tool **[http://www.boost.org/libs/regex/doc/index.html Boost.Regex: Index], boost.regex library for regular expression parser in C++ **[http://regex.osherove.com/ The Regulator] The Regulator is an advanced, free regular expressions testing and learning tool. It allows you to build and verify a regular expression against any text input, file or web, and displays matching, splitting or replacement results within an easy to understand, hierarchical tree. **[http://www.renatomancuso.com/software/pcreworkbench/pcreworkbench.htm PCRE Workbench] Formal languages Mathematical logic Computer science Pattern matching

Regular expression



== First paragraph == I have added an introductory paragraph before the history section, explaining by means of example the basic regex operations. This used to be buried in the formal language theory section, which makes it opaque to a lay audience. This led to some minor edits in the formal language section. == Notation and style == The Manual of Style suggests that strings as strings should appear in italics. This convention doesn't make the current page harder to read, so I have edited some passages with that convention in mind. Some questions remain: how should regular expressions be formatted in this article? They currently appear mostly in double quotes (inch-marks), like this: # the regular expression "gr(e|a)y" matches ''grey'' and ''gray''. I think that works well, provided we do not add many expressions that include quotation marks. Alternatives would be to use the same convention as for strings: # the regular expression ''gr(e|a)y'' matches ''grey'' and ''gray'' Alternatives include bold face, not least for readability # the regular expression gr(e|a)y matches ''grey'' and ''gray'' or a fixed width typeface, also for readability and proximity to program code # the regular expression gr(a|e)y matches ''grey'' and ''gray'' A alternative solution to the double quotes would be to always present them in slashes, to make it look like perl # /gr(a|e)y/ matches ''grey'' and ''gray'' Opinions are welcome. On a related matter, I have replaced the union operator ∪ with the vertical bar even in the formal language theory section. I can count at least four different symbols for this in the literature (including the vertical bar), and suggest we use the vertical bar to keep the connection with programming tools and reduce the number of symbols in this article. Moreover, the choice of default typeface for the Wikipedia leads to a problem for this page, in that there is no distinction between the lowercase letter “l” and the vertical bar “|”. That makes some of the regexes really hard to read, and could be taken as a point in favour of displaying all regexes in the monospaced typeface. Here is an example of two lower-case Ls separated by a vertical bar: “l|l” in the default typeface, and “l|l” in the default monospace. == Complexity == Under Perl Regexp it states: "This extra power comes at a cost. The worst-case complexity of matching a string against a Perl regular expression is exponential in the size of the input. That means the regular expression could take an extremely long time to process under just the right conditions of expression and input string, although it rarely happens in practice." Isn't this also true for POSIX and all flavours using an NFA? --User:Weinzier 18:12, 12 Jul 2004 (UTC) Ludwig Weinzierl : NFAs can recognize strings in linear time (in the size of the input). I don't know POSIX well enough to comment on that. -- User:Jan Hidders 20:00, 12 Jul 2004 (UTC) :: LW is right. The exponential running time is not caused by nonregularity (instead it has to do with greediness and/or the ability to make backreferences). Indeed, the nonregularity does not "come at a cost", but is included pretty much because the engine might as well execute some Perl code while it's there (so you can implement a stack, or save substrings). So it would be more correct (but still misleading) to say it "comes for free". I have removed the whole paragraph. -- User:Thore ::: I don't follow. The greediness and backreferences are what makes it non-regular, (by having them things become non-polynomial, and if we would not have them then it would stay polynomial) so if I understand you correctly you are in fact above confirming the very thing that you claim is not true. What am I missing? -- User:Jan Hidders 20:41, 8 Dec 2004 (UTC) :::: Jan, let me try to explain this better. The thing that causes nonregularity are the backreferences. They are not specific to Perl. The thing that causes the nonlinear running time is the implementation often referred to as NFA, which is just a "backtracking" algorithm. (Rather than simulating a determinised automaton, which is sometimes called DFA, and always runs in linear time.) That's an inaccuracy in your first paragraph on this page, by the way. "NFA implementations" like Perl's are decidedly non-linear time. Friedl's book tries to explain this in Chapter 6. Let me see if I can write a few paragraphs about this on the main page, and then you can all shoot it down. -- User:Thore ---- * character classes, with negation: [a-z0-9^4-6] ('all lowercase letters plus the digits --- 0,1,2,3,7,8, and 9') request verification: ''"[^" requests negation; a "^" not following the first "[" is taken literally; so this is all lowercase letters, all digits, and "^"'' ---- Correct. My 'vi' and 'grep' agree with you. I will remove it. -- JanHidders ---- In the examples section of the Regular expressions in Formal Language Theory it states that (a U b)* is equivalent to (ab*)* However, the first set contains "b", the second does not. : Indeed, all non-empty strings in the second set start with "a" which is of course not the case in the first set. Fixed now. -- User:Jan Hidders 12:55, 19 Sep 2003 (UTC) ---- ==Programmers' T-shirt pic== hmm... good one.. but Diet Coke is getting some free publicity ! User:Jay 13:26, 17 Jun 2004 (UTC) :I prefer the tee-shirt imaged at http://www.thinkgeek.com/tshirts/coder/57f0/ . I wonder if there is any way that we can use that image instead? Probably not, unless one of us orders one and snaps a picture while wearing it. - User:Bevo 14:46, 17 Jun 2004 (UTC) Must admit, I hate Diet Coke, and this picture is not going to convert me — simply thought it looked very typical; and mimicking the FedEx logo is so obvious. (The Shakespeare quote is also cute.) --User:Palapala 16:05, 2004 Jun 17 (UTC) I have no objection to the picturing of diet coke here, however it's hard to find an adacute picture for this article. --User:Ævar Arnfjörð Bjarmason 22:35, 2004 Jul 12 (UTC) I think the pic should go altogether, or at least it shouldn't be at the very start. It doesn't add anything useful or essential to the article, but rather distracts attention. This is supposed to be about ''regular expressions'', not geek culture or t-shirts or whatever. --User:Jonik 13:11, 22 Jan 2005 (UTC) :I agreee. User:Edward 19:33, 2005 Jan 22 (UTC) == T shirt text == I'm sorry to say it so but that "skript kiddie" t-shirt regexp states for "Hack the planet" with some haxx0r variations: h@<User:Tordek ar 19:34, 3 Sep 2004 (UTC) == Be more generic == Don't want to start any arguments, but where the page says "Ever since that time, regular expressions have been widely used in Unix and Unix-like utilities such as: expr, awk, Emacs, vim, lex, and Perl.", shouldn't it really mention vi, not vim. Agree? User:Celada 00:28, 2004 Nov 19 (UTC) : Agree! -- User:Jan Hidders 16:14, 19 Nov 2004 (UTC) :: OK, done! User:Celada 03:31, 2004 Nov 20 (UTC) == Regex versus regular expression == User:Porge replaced a number of occurences of the term ''regex'' with ''regular expression''. However, this may not be as straightforward as expanding an abbreviation with a longer form. One of the big problems with this pages is that regular expression means different things to different people. Especially, not all regexes are formal language theory regular expressions. The previous version of this page tried to use the term ''regular expression'' only for those constructs that are regular in both senses of the word, using the term regex for irregular patterns. The article also contains a paragraph about this policy, and tried to follow that policy itself. However, form User:Porge's edits that may not be a universally appreciated policy. Maybe we can discuss it here. There are certainly many, many ways to resolve the issue. (For example, by separating the pages.) However, I think this article has a lot of potential and actually tries to explain something, so I would be in favour of keeping both meanings under one hood, and retaining the subtle nomenclature. Other opinions are welcome. (Larry Wall in one of his Perl 6 apocalypses suggests to just use ''pattern'', and get rid of the connection to (Formal Language) regular expressions altogether.) User:Arbor 07:25, 20 May 2005 (UTC) :I don't think this is a widely accepted distinction - I don't remember ever seeing it before. --User:Khendon 19:00, 20 May 2005 (UTC) ::Sorry if I've removed a distinction, I was just trying to standardize the word across the article (in various places it had regexp, regex or regular expression). I'm not experienced enough in this area to comment on the formal versus implemented side of things, although I've never heard of the nomenclature being used to protray the difference. User:Porge 19:52, May 20, 2005 (UTC) :::I never claimed the distinction was widely accepted. I introduced it when I tried to clean up the article; the idea is certainly up for debate. The solution had the advantage of not calling overmuch attention to itself (compared to, say, using phrases like ''non-regular regular expressions'') but at the same time surviving a close examination (because nowhere was a regex called regular when it wasn't). No matter how we solve this, I would maintain the position that the present article should aim to ''minimise confusion'', which includes being very precise about ''not'' using the term regular expression for patterns that don't conform to the term in all its meanings. (Alternatively, the language-theoretical use needs to be split off, which would make the article less interesting in my opinion.) The nomenclature is bad enough as it is (pointed out and commented on in both Schwartz's book and Wall's writings), and Wikipedia shouldn't add to the confusion. However, other suggestions are more than welcome. (I would prefer to just use pattern for all those regexes that aren't regular expressions.) User:Arbor 20:09, 20 May 2005 (UTC) ::::I'd prefer "pattern" over "regex" for irregular regular expressions. The latter is too ambiguous. :) User:Porge 09:13, May 21, 2005 (UTC) == Javascript and escaping minus == Javascripts regex.test () do not match '-' (minus sign) for [-a-z] like, for example, Perl does. Javascript requires that '-' is escaped with [\-a-z]. (Tested in Firefox.) * The article says: "The '-' character should be literal only if it is the last or the first character within the brackets: [abc-] or [-abc].". Suggestion: Note that this does not work in some implementations like Javascript and that '\-' is better (this works in all implementations?) and clearer. * The article also says: "Since the characters '(', ')', '[', ']', '.', '*', '?', '+', '^' and '$' are used as special symbols they have to be "escaped" somehow if they are meant literally. This is done by preceding them with '\'". Suggestion: Mention that '-' ''should'' (not must) be escaped as well. It's a small detail, but it would have helped me a fiew moments ago. :) Kricke 14:38, 17 june 2005 (CET). == Alternation character and text appearance == On my computer (Mac running safari) the alternation character as seen here is nearly indistinguishable from a lower-case L. (The font is Arial, I believe -- if your theme matches mine, see for yourself: | l ) In some examples this makes comprehension difficult -- for example, I read the first expression in the line 'For example, "gr(a|e)y" is the same as "gray|grey"' as "gr(ALE)y", and since there's no direct reference to alternation in the explanation of the example, I had to rely on my knowledge of regexps to figure out that the character was an alternation operator. One solution to this problem would be to use the TeX equivalent of the character. Another would be to put all regular expression examples in code form, as suggested above: For example, gr(a|e)y is the same as gray|grey I think the latter (code-style) is preferable, but there may be larger Wikipedia style issues at play. Does anyone have any comments or suggestions? Either way the problem should be resolved. User:Adam ConoverUser:Adam Conover User talk:Adam Conover 17:23, Jun 20, 2005 (UTC) : I tried to discuss the issue further up. You correctly point out a big problem with this page. User:Arbor 18:31, 20 Jun 2005 (UTC)


See other meanings of words starting from letter:

R

RA | RB | RC | RD | RE | RF | RG | RH | RI | RJ | RK | RL | RM | RN | RO | RP | RS | RT | RU | RW | RX | RY | RZ |

Words begining with Regular_expression:

Regular_Expression
Regular_expression
Regular_expression
Regular_Expressions
Regular_expressions


These materials are based on Wikipedia and licensed under the GNU FDL



YouTube.com videos better site than Turbo Tax 2007
encyklopedia online