A Quick Guide to PERL Regular Expressions Second Edition © 2006 Transliteration: Translate Operator Tr/// EXPR =~ Tr/SEARCHLIST/REPLACELIST/Cds

Total Page:16

File Type:pdf, Size:1020Kb

A Quick Guide to PERL Regular Expressions Second Edition © 2006 Transliteration: Translate Operator Tr/// EXPR =~ Tr/SEARCHLIST/REPLACELIST/Cds \W Any non-word character. Warning \w != \S Search&Replace: substitution operator s/// A Quick Guide To EXPR =~ s/MOTIF/REPLACE/egimosx POSIX Character class PERL Regular Expressions Example: correct typo for the word rabbit [[:class:]] class can be any of: $ex =~ s/rabit/rabbit/g; alnum alpha ascii blank cntrl digit graph lower This is a Quick reference Guide for PERL regular expressions Here is the content of $ex: print punct space upper xdigit (also known as regexps or regexes). The ID sp:UBP5_RAT is similar to the rabbit AC tr:Q12345 These tools are used to describe text as “motifs” or “patterns” for matching, quoting, substituting or translitterating. Each Example: find and tag any TrEMBL AC Special characters programming language (Perl, C, Java, Python...) define its $ex =~ s/tr:/trembl_ac=/g; \a alert (bell) Here is the content of $ex: own regular expressions although the syntax might differ from \b backspace details to extensive changes. In this guide we will concentrate The ID sp:UBP5_RAT is similar to the rabit AC trembl_ \e escape ac=Q12345 on the Perl regexp syntax, we assume that the reader has some \f form feed preliminary knowledge of Perl programming. Options \n newline \r carriage return e evaluate REPLACE as an expression Perl uses a Traditional Nondeterministic Finite Automata \t horizontal tabulation (NFA) match engine. This means that it will compare each g global matches (matches all occurrences) element of the motif to the input string, keeping track of i case insensitive \nnn octal nnn the positions. The engine choose the first leftmost match m multiline, allow “^” and “$” to match with (\n) \xnn hexadecimal nn after greedy (i.e., longest possible match) quantifiers have o compile MOTIF only once \cX control character X matched. s single line, dot “.” matches new-line (\n) x ignore whitespace and allow comments “#” in MOTIF References Repetitions For more information on Perl regexps and other syntaxes Zero or one occurrence of the previous item. you can refer to O’Reilly’s book “Mastering Regular Quoting: quote and compile operator qr// ? Zero or more occurrences of the previous item. Expressions”. EXPR =~ qr/MOTIF/imosx * + One or more occurrences of the previous item. Examples: Example: reuse of a precompiled regexp Match at least times but no more than times the The following sentence will be used in all our examples: $myregexp = qr/\w{2,5}_\w{2,5}/; {n,m} n m previous item. The ID sp:UBP5_RAT is similar to the rabit AC tr:Q12345 if ($ex =~ m/$myregexp/) { print “SwissProtID\n”; } will match: {n,} Match n or more times The ID sp:UBP5_RAT is similar to the rabit AC tr:Q12345 {n} Match exactly n times Motif finding: match operator m// and as a result will print SwissProtID. {}? Non-greedy match (i.e., match the shortest string) EXPR =~ m/MOTIF/cgimosx EXPR =~ /MOTIF/cgimosx Options EXPR !~ m/MOTIF/cgimosx i case insensitive Anchors EXPR !~ /MOTIF/cgimosx m multiline, allow “^” and “$” to match with (\n) ^ or \A Match beginning of the string/line o compile MOTIF only once $ or \Z Match end of the string/line Examples: match any SwissProt ID for a rat protein s single line, dot “.” matches new-line (\n) \z End of string in any match mode if ($ex =~ m/\w{2,5}_RAT/) { print “Rat entry\n”; } ignore whitespace and allow comments in MOTIF \b Match word boundary will match x “#” \B Match non-word boundary The ID sp:UBP5_RAT is similar to the rabit AC tr:Q12345 and as a result print Rat entry. Character classes Capture & Grouping Options [...] Match any one character of a class [^...] Match any one character not in the bracket (...) Group several characters together for later use or cg continue after a failure in /g . Match any character (except newline [^\n]) in non capture as a single unit g global matches (matches all occurrences) single-line mode (/s) | Match either subexpressions (equivalent to “OR”) i case insensitive \d Any digit. Equivalent to [0..9] or [[:digit:]] m multiline, allow “^” and “$” to match with (\n) \D Any non-digit. Example: match any database code in the list o compile MOTIF only once \s Any whitespace. [ \t\s\n\r\f\v] or [[:space:]] $ex =~ m/(sp:|tr:|rs:)/g; s single line, dot “.” matches new-line (\n) \S Any non-whitespace. will match: x ignore whitespace and allow comments “#” in MOTIF \w Any word character. [a-zA-Z0-9_] or [[:alnum:_]] The ID sp:UBP5_RAT is similar to the rabit AC tr:Q12345 \n Back reference. Match the same as the captured Example: reverse and complement a DNA sequence group number n that was previously matched in $DNA = AAATATTTCATCGTACAT; the same MOTIF. $revcom = reverse $DNA; $n Substring of captured group n $revcom =~ tr/ACGTacgt/TGCAtgca/; Example: match several instances with back reference $ex =~ m/(the).+\1/i; will match: The ID sp:UBP5_RAT is similar to the rabit AC tr:Q12345 The transliteration will produce the following: print($DNA); AAATATTTCATCGTACAT print($revcom); Example: rename any tr:AC to trembl_AC= using a capture ATGTACGATGAAATATTT $ex =~ s/tr:([[:alnum:]]{6})/trembl_AC=$1/gi; will match: Options complement REPLACELIST The ID sp:UBP5_RAT is similar to the rabit AC trembl_ c AC=Q12345 d delete non-replaced characters s single replace of duplicated characters UniCode matches Perl 5.8 supports UniCode 3.2. However it would be too long to describe all the properties in details here. For more information see “Mastering Regular Expressions”. Text-span modifiers \p{PROP} Matches a UniCode property Quote following metacharacters until or end of \Q \E \P{PROP} Matches anything but a UniCode property motif (allow the use of scalars in regexp) \u Force next character to uppercase \l Force next character to lowecase This document was written and designed by Laurent Falquet \U Force all following characters to uppercase and Vassilios Ioannidis from the Swiss EMBnet node and being \L Force all following characters to lowercase distributed by P&PR Publications Committee of EMBnet. \E End a span started with \Q, \U or \L EMBnet - European Molecular Biology Network - is a bioinformatics support network of bioinformatics support Extended Regexp centers situated primarily in Europe. Most countries have a (?#...) Substring “...” is a comment national node which can provide training courses and other forms of help for users of bioinformatics software. (?=...) Positive lookahead. Match if exists next match (e.g., allow overlapping matches in global mode) You can find information about your national node from the Negative lookahead. Match if no next match (?!...) EMBnet site: (?<=...) Positive lookbehind. Fixed length only. Negative lookbehind. Fixed length only. (?<!...) http://www.embnet.org/ (?imsx) Modify matching options A Quick Guide To PERL Regular Expressions Second edition © 2006 Transliteration: translate operator tr/// EXPR =~ tr/SEARCHLIST/REPLACELIST/cds Transliteration is not - and does not use - a regular expression, but it is frequently associated with the regexp in PERL. Thus we decided to include it in this guide..
Recommended publications
  • Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA
    NESUG 2007 Programming Beyond the Basics Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA ABSTRACT Regular Expression (Regexp) enhance search and replace operations on text. In SAS®, the INDEX, SCAN and SUBSTR functions along with concatenation (||) can be used for simple search and replace operations on static text. These functions lack flexibility and make searching dynamic text difficult, and involve more function calls. Regexp combines most, if not all, of these steps into one expression. This makes code less error prone, easier to maintain, clearer, and can improve performance. This paper will discuss three ways to use Perl Regular Expression in SAS: 1. Use SAS PRX functions; 2. Use Perl Regular Expression with filename statement through a PIPE such as ‘Filename fileref PIPE 'Perl programm'; 3. Use an X command such as ‘X Perl_program’; Three typical uses of regular expressions will also be discussed and example(s) will be presented for each: 1. Test for a pattern of characters within a string; 2. Replace text; 3. Extract a substring. INTRODUCTION Perl is short for “Practical Extraction and Report Language". Larry Wall Created Perl in mid-1980s when he was trying to produce some reports from a Usenet-Nes-like hierarchy of files. Perl tries to fill the gap between low-level programming and high-level programming and it is easy, nearly unlimited, and fast. A regular expression, often called a pattern in Perl, is a template that either matches or does not match a given string. That is, there are an infinite number of possible text strings.
    [Show full text]
  • Lecture 18: Theory of Computation Regular Expressions and Dfas
    Introduction to Theoretical CS Lecture 18: Theory of Computation Two fundamental questions. ! What can a computer do? ! What can a computer do with limited resources? General approach. Pentium IV running Linux kernel 2.4.22 ! Don't talk about specific machines or problems. ! Consider minimal abstract machines. ! Consider general classes of problems. COS126: General Computer Science • http://www.cs.Princeton.EDU/~cos126 2 Why Learn Theory In theory . Regular Expressions and DFAs ! Deeper understanding of what is a computer and computing. ! Foundation of all modern computers. ! Pure science. ! Philosophical implications. a* | (a*ba*ba*ba*)* In practice . ! Web search: theory of pattern matching. ! Sequential circuits: theory of finite state automata. a a a ! Compilers: theory of context free grammars. b b ! Cryptography: theory of computational complexity. 0 1 2 ! Data compression: theory of information. b "In theory there is no difference between theory and practice. In practice there is." -Yogi Berra 3 4 Pattern Matching Applications Regular Expressions: Basic Operations Test if a string matches some pattern. Regular expression. Notation to specify a set of strings. ! Process natural language. ! Scan for virus signatures. ! Search for information using Google. Operation Regular Expression Yes No ! Access information in digital libraries. ! Retrieve information from Lexis/Nexis. Concatenation aabaab aabaab every other string ! Search-and-replace in a word processors. cumulus succubus Wildcard .u.u.u. ! Filter text (spam, NetNanny, Carnivore, malware). jugulum tumultuous ! Validate data-entry fields (dates, email, URL, credit card). aa Union aa | baab baab every other string ! Search for markers in human genome using PROSITE patterns. aa ab Closure ab*a abbba ababa Parse text files.
    [Show full text]
  • Perl Regular Expressions Tip Sheet Functions and Call Routines
    – Perl Regular Expressions Tip Sheet Functions and Call Routines Basic Syntax Advanced Syntax regex-id = prxparse(perl-regex) Character Behavior Character Behavior Compile Perl regular expression perl-regex and /…/ Starting and ending regex delimiters non-meta Match character return regex-id to be used by other PRX functions. | Alternation character () Grouping {}[]()^ Metacharacters, to match these pos = prxmatch(regex-id | perl-regex, source) $.|*+?\ characters, override (escape) with \ Search in source and return position of match or zero Wildcards/Character Class Shorthands \ Override (escape) next metacharacter if no match is found. Character Behavior \n Match capture buffer n Match any one character . (?:…) Non-capturing group new-string = prxchange(regex-id | perl-regex, times, \w Match a word character (alphanumeric old-string) plus "_") Lazy Repetition Factors Search and replace times number of times in old- \W Match a non-word character (match minimum number of times possible) string and return modified string in new-string. \s Match a whitespace character Character Behavior \S Match a non-whitespace character *? Match 0 or more times call prxchange(regex-id, times, old-string, new- \d Match a digit character +? Match 1 or more times string, res-length, trunc-value, num-of-changes) Match a non-digit character ?? Match 0 or 1 time Same as prior example and place length of result in \D {n}? Match exactly n times res-length, if result is too long to fit into new-string, Character Classes Match at least n times trunc-value is set to 1, and the number of changes is {n,}? Character Behavior Match at least n but not more than m placed in num-of-changes.
    [Show full text]
  • Unicode Regular Expressions Technical Reports
    7/1/2019 UTS #18: Unicode Regular Expressions Technical Reports Working Draft for Proposed Update Unicode® Technical Standard #18 UNICODE REGULAR EXPRESSIONS Version 20 Editors Mark Davis, Andy Heninger Date 2019-07-01 This Version http://www.unicode.org/reports/tr18/tr18-20.html Previous Version http://www.unicode.org/reports/tr18/tr18-19.html Latest Version http://www.unicode.org/reports/tr18/ Latest Proposed http://www.unicode.org/reports/tr18/proposed.html Update Revision 20 Summary This document describes guidelines for how to adapt regular expression engines to use Unicode. Status This is a draft document which may be updated, replaced, or superseded by other documents at any time. Publication does not imply endorsement by the Unicode Consortium. This is not a stable document; it is inappropriate to cite this document as other than a work in progress. A Unicode Technical Standard (UTS) is an independent specification. Conformance to the Unicode Standard does not imply conformance to any UTS. Please submit corrigenda and other comments with the online reporting form [Feedback]. Related information that is useful in understanding this document is found in the References. For the latest version of the Unicode Standard, see [Unicode]. For a list of current Unicode Technical Reports, see [Reports]. For more information about versions of the Unicode Standard, see [Versions]. Contents 0 Introduction 0.1 Notation 0.2 Conformance 1 Basic Unicode Support: Level 1 1.1 Hex Notation 1.1.1 Hex Notation and Normalization 1.2 Properties 1.2.1 General
    [Show full text]
  • Regular Expressions with a Brief Intro to FSM
    Regular Expressions with a brief intro to FSM 15-123 Systems Skills in C and Unix Case for regular expressions • Many web applications require pattern matching – look for <a href> tag for links – Token search • A regular expression – A pattern that defines a class of strings – Special syntax used to represent the class • Eg; *.c - any pattern that ends with .c Formal Languages • Formal language consists of – An alphabet – Formal grammar • Formal grammar defines – Strings that belong to language • Formal languages with formal semantics generates rules for semantic specifications of programming languages Automaton • An automaton ( or automata in plural) is a machine that can recognize valid strings generated by a formal language . • A finite automata is a mathematical model of a finite state machine (FSM), an abstract model under which all modern computers are built. Automaton • A FSM is a machine that consists of a set of finite states and a transition table. • The FSM can be in any one of the states and can transit from one state to another based on a series of rules given by a transition function. Example What does this machine represents? Describe the kind of strings it will accept. Exercise • Draw a FSM that accepts any string with even number of A’s. Assume the alphabet is {A,B} Build a FSM • Stream: “I love cats and more cats and big cats ” • Pattern: “cat” Regular Expressions Regex versus FSM • A regular expressions and FSM’s are equivalent concepts. • Regular expression is a pattern that can be recognized by a FSM. • Regex is an example of how good theory leads to good programs Regular Expression • regex defines a class of patterns – Patterns that ends with a “*” • Regex utilities in unix – grep , awk , sed • Applications – Pattern matching (DNA) – Web searches Regex Engine • A software that can process a string to find regex matches.
    [Show full text]
  • Regular Expressions
    CS 172: Computability and Complexity Regular Expressions Sanjit A. Seshia EECS, UC Berkeley Acknowledgments: L.von Ahn, L. Blum, M. Blum The Picture So Far DFA NFA Regular language S. A. Seshia 2 Today’s Lecture DFA NFA Regular Regular language expression S. A. Seshia 3 Regular Expressions • What is a regular expression? S. A. Seshia 4 Regular Expressions • Q. What is a regular expression? • A. It’s a “textual”/ “algebraic” representation of a regular language – A DFA can be viewed as a “pictorial” / “explicit” representation • We will prove that a regular expressions (regexps) indeed represent regular languages S. A. Seshia 5 Regular Expressions: Definition σ is a regular expression representing { σσσ} ( σσσ ∈∈∈ ΣΣΣ ) ε is a regular expression representing { ε} ∅ is a regular expression representing ∅∅∅ If R 1 and R 2 are regular expressions representing L 1 and L 2 then: (R 1R2) represents L 1⋅⋅⋅L2 (R 1 ∪∪∪ R2) represents L 1 ∪∪∪ L2 (R 1)* represents L 1* S. A. Seshia 6 Operator Precedence 1. *** 2. ( often left out; ⋅⋅⋅ a ··· b ab ) 3. ∪∪∪ S. A. Seshia 7 Example of Precedence R1*R 2 ∪∪∪ R3 = ( ())R1* R2 ∪∪∪ R3 S. A. Seshia 8 What’s the regexp? { w | w has exactly a single 1 } 0*10* S. A. Seshia 9 What language does ∅∅∅* represent? {ε} S. A. Seshia 10 What’s the regexp? { w | w has length ≥ 3 and its 3rd symbol is 0 } ΣΣΣ2 0 ΣΣΣ* Σ = (0 ∪∪∪ 1) S. A. Seshia 11 Some Identities Let R, S, T be regular expressions • R ∪∪∪∅∅∅ = ? • R ···∅∅∅ = ? • Prove: R ( S ∪∪∪ T ) = R S ∪∪∪ R T (what’s the proof idea?) S.
    [Show full text]
  • Context-Free Grammar for the Syntax of Regular Expression Over the ASCII
    Context-free Grammar for the syntax of regular expression over the ASCII character set assumption : • A regular expression is to be interpreted a Haskell string, then is used to match against a Haskell string. Therefore, each regexp is enclosed inside a pair of double quotes, just like any Haskell string. For clarity, a regexp is highlighted and a “Haskell input string” is quoted for the examples in this document. • Since ASCII character strings will be encoded as in Haskell, therefore special control ASCII characters such as NUL and DEL are handled by Haskell. context-free grammar : BNF notation is used to describe the syntax of regular expressions defined in this document, with the following basic rules: • <nonterminal> ::= choice1 | choice2 | ... • Double quotes are used when necessary to reflect the literal meaning of the content itself. <regexp> ::= <union> | <concat> <union> ::= <regexp> "|" <concat> <concat> ::= <term><concat> | <term> <term> ::= <star> | <element> <star> ::= <element>* <element> ::= <group> | <char> | <emptySet> | <emptyStr> <group> ::= (<regexp>) <char> ::= <alphanum> | <symbol> | <white> <alphanum> ::= A | B | C | ... | Z | a | b | c | ... | z | 0 | 1 | 2 | ... | 9 <symbol> ::= ! | " | # | $ | % | & | ' | + | , | - | . | / | : | ; | < | = | > | ? | @ | [ | ] | ^ | _ | ` | { | } | ~ | <sp> | \<metachar> <sp> ::= " " <metachar> ::= \ | "|" | ( | ) | * | <white> <white> ::= <tab> | <vtab> | <nline> <tab> ::= \t <vtab> ::= \v <nline> ::= \n <emptySet> ::= Ø <emptyStr> ::= "" Explanations : 1. Definition of <metachar> in our definition of regexp: Symbol meaning \ Used to escape a metacharacter, \* means the star char itself | Specifies alternatives, y|n|m means y OR n OR m (...) Used for grouping, giving the group priority * Used to indicate zero or more of a regexp, a* matches the empty string, “a”, “aa”, “aaa” and so on Whi tespace char meaning \n A new line character \t A horizontal tab character \v A vertical tab character 2.
    [Show full text]
  • PHP Regular Expressions
    PHP Regular Expressions What is Regular Expression Regular Expressions, commonly known as "regex" or "RegExp", are a specially formatted text strings used to find patterns in text. Regular expressions are one of the most powerful tools available today for effective and efficient text processing and manipulations. For example, it can be used to verify whether the format of data i.e. name, email, phone number, etc. entered by the user was correct or not, find or replace matching string within text content, and so on. PHP (version 5.3 and above) supports Perl style regular expressions via its preg_ family of functions. Why Perl style regular expressions? Because Perl (Practical Extraction and Report Language) was the first mainstream programming language that provided integrated support for regular expressions and it is well known for its strong support of regular expressions and its extraordinary text processing and manipulation capabilities. Let's begin with a brief overview of the commonly used PHP's built-in pattern- matching functions before delving deep into the world of regular expressions. Function What it Does preg_match() Perform a regular expression match. preg_match_all() Perform a global regular expression match. preg_replace() Perform a regular expression search and replace. preg_grep() Returns the elements of the input array that matched the pattern. preg_split() Splits up a string into substrings using a regular expression. preg_quote() Quote regular expression characters found within a string. Note: The PHP preg_match() function stops searching after it finds the first match, whereas the preg_match_all() function continues searching until the end of the string and find all possible matches instead of stopping at the first match.
    [Show full text]
  • CSCI 3434: Theory of Computation Lecture 4: Regular Expressions
    CSCI 3434: Theory of Computation Lecture 4: Regular Expressions Ashutosh Trivedi 0; 1 0; 1 1 0;" 1 start s1 s2 s3 s4 Department of Computer Science University of Colorado Boulder Ashutosh Trivedi { 1 of 21 Ashutosh Trivedi Lecture 3: Regular Expressions Definition (Regular Languages) We call a language regular if it can be accepted by a deterministic finite state automaton. What are Regular Languages? { An alphabet Σ = fa; b; cg is a finite set of letters, { The set of all strings (aka, words) Σ∗ over an alphabet Σ can be recursively defined as: as : { Base case: " 2 Σ∗ (empty string), { Induction: If w 2 Σ∗ then wa 2 Σ∗ for all a 2 Σ. {A language L over some alphabet Σ is a set of strings, i.e. L ⊆ Σ∗. { Some examples: ∗ { Leven = fw 2 Σ : w is of even lengthg ∗ n m { La∗b∗ = fw 2 Σ : w is of the form a b for n; m ≥ 0g ∗ n n { Lanbn = fw 2 Σ : w is of the form a b for n ≥ 0g ∗ 0 { Lprime = fw 2 Σ : w has a prime number of a sg { Deterministic finite state automata define languages that require finite resources (states) to recognize. Ashutosh Trivedi { 2 of 21 Ashutosh Trivedi Lecture 3: Regular Expressions What are Regular Languages? { An alphabet Σ = fa; b; cg is a finite set of letters, { The set of all strings (aka, words) Σ∗ over an alphabet Σ can be recursively defined as: as : { Base case: " 2 Σ∗ (empty string), { Induction: If w 2 Σ∗ then wa 2 Σ∗ for all a 2 Σ.
    [Show full text]
  • 10 Patterns, Automata, and Regular Expressions
    CHAPTER 10 Patterns, Automata, ✦ ✦ ✦ ✦ and Regular Expressions A pattern is a set of objects with some recognizable property. One type of pattern is a set of character strings, such as the set of legal C identifiers, each of which is a string of letters, digits, and underscores, beginning with a letter or underscore. Another example would be the set of arrays of 0’s and 1’s of a given size that a character reader might interpret as representing the same symbol. Figure 10.1 shows three 7 × 7-arrays that might be interpreted as letter A’s. The set of all such arrays would constitute the pattern called “A.” 0001000 0000000 0001000 0011100 0010000 0010100 0010100 0011000 0110100 0110110 0101000 0111110 0111110 0111000 1100011 1100011 1001100 1000001 1000001 1000100 0000000 Fig. 10.1. Three instances of the pattern “A.” The two fundamental problems associated with patterns are their definition and their recognition, subjects of this and the next chapter. Recognizing patterns is an integral part of tasks such as optical character recognition, an example of which was suggested by Fig. 10.1. In some applications, pattern recognition is a component of a larger problem. For example, recognizing patterns in programs is an essential part of compiling — that is, the translation of programs from one language, such as C, into another, such as machine language. There are many other examples of pattern use in computer science. Patterns play a key role in the design of the electronic circuits used to build computers and other digital devices. They are used in text editors to allow us to search for instances of specific words or sets of character strings, such as “the letters if followed by any sequence of characters followed by then.” Most operating systems allow us to use 529 530 PATTERNS, AUTOMATA, AND REGULAR EXPRESSIONS patterns in commands; for example, the UNIX command “ls *tex” lists all files whose names end with the three-character sequence “tex”.
    [Show full text]
  • Regular Expressions for Perl, C, PHP, Python, Java, and .NET
    Regular Expressions for Perl, C, PHP, Python, Java, and .NET Regular Expression Pocket Reference Tony Stubblebine Regular Expression Pocket Reference Regular Expression Pocket Reference Tony Stubblebine Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo PHP This reference covers PHP 4.3’s Perl-style regular expression support contained within the preg routines. PHP also pro- vides POSIX-style regular expressions, but these do not offer additional benefit in power or speed. The preg routines use a Traditional NFA match engine. For an explanation of the rules behind an NFA engine, see “Introduction to Regexes and Pattern Matching.” Supported Metacharacters PHP supports the metacharacters and metasequences listed in Tables 31 through 35. For expanded definitions of each metacharacter, see “Regex Metacharacters, Modes, and Constructs.” Table 31. Character representations Sequence Meaning \a Alert (bell), x07. \b Backspace, x08, supported only in character class. \e ESC character, x1B. \n Newline, x0A. \r Carriage return, x0D. \f Form feed, x0C. \t Horizontal tab, x09 \octal Character specified by a three-digit octal code. \xhex Character specified by a one- or two-digit hexadecimal code. \x{hex} Character specified by any hexadecimal code. \cchar Named control character. Table 32. Character classes and class-like constructs Class Meaning [...] A single character listed or contained within a listed range. PHP | 63 Table 32. Character classes and class-like constructs Class Meaning [^...] A single character not listed and not contained within a listed range. [:class:] POSIX-style character class valid only within a regex character class. Any character except newline (unless single-line mode,/s). \C One byte; however, this may corrupt a Unicode character stream.
    [Show full text]
  • Regular Languages and Finite Automata for Part IA of the Computer Science Tripos
    N Lecture Notes on Regular Languages and Finite Automata for Part IA of the Computer Science Tripos Prof. Andrew M. Pitts Cambridge University Computer Laboratory c 2010 A. M. Pitts First Edition 1998. Revised 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010. Contents Learning Guide ii 1 Regular Expressions 1 1.1 Alphabets, strings, and languages . ...... 1 1.2 Patternmatching ................................ 4 1.3 Some questions about languages . ... 6 1.4 Exercises .................................... 8 2 Finite State Machines 11 2.1 Finiteautomata ................................. 11 2.2 Determinism, non-determinism, and ε-transitions . 14 2.3 Asubsetconstruction . .... .... .... ..... .... .... ... 17 2.4 Summary .................................... 20 2.5 Exercises .................................... 20 3 Regular Languages, I 23 3.1 Finite automata from regular expressions . ........ 23 3.2 Decidabilityofmatching . 28 3.3 Exercises .................................... 30 4 Regular Languages, II 31 4.1 Regular expressions from finite automata . ..... 31 4.2 Anexample ................................... 32 4.3 Complement and intersection of regular languages . ......... 34 4.4 Exercises .................................... 36 5 The Pumping Lemma 39 5.1 ProvingthePumpingLemma. 40 5.2 UsingthePumpingLemma.. .... .... ..... .... .... .... 41 5.3 Decidability of language equivalence . ....... 44 5.4 Exercises .................................... 45 6 Grammars 47 6.1 Context-freegrammars . 47 6.2 Backus-NaurForm ..............................
    [Show full text]