Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)
|
|
- Dale Chambers
- 5 years ago
- Views:
Transcription
1 Regular Expressions Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) JavaScript started supporting regular expressions in version 1.4 of the language, which means they will only work in Netscape 4 or Internet Explorer 4 web browsers, or subsequent releases. A regular expression is a sequence of characters written using a special regular expression language, which can be used to match patterns in other strings. 1 of 49
2 Example: <script> function check(){ var re5digit=/^\d{5}$/ //regular expression defining //a 5 digit number if (document.myform.myinput.value.search (re5digit)==-1) alert("please enter a valid 5 digit number inside form") } </script> 2 of 49
3 <form name="myform"> <input type="text" name="myinput" size=15> <input type="button" onclick="checkpostal()" value="check"> </form> 3 of 49
4 Let us deconstruct the regular expression used, which checks that a string contains a valid 5-digit number, and ONLY a 5- digit number: var re5digit=/^\d{5}$/ ^ indicates the beginning of the string. Using a ^ metacharacter requires that the match start at the beginning. \d indicates a digit character and the {5} following it means that there must be 5 consecutive digit characters. $ indicates the end of the string. Using a $ metacharacter requires that the match end at the end of the string. 4 of 49
5 This pattern states: "Starting at the beginning of the string there must be nothing other than 5 digits. There must also be nothing following those 5 digits." 5 of 49
6 Example: Check if a string matches the US standard telephone number format (XXX) XXX XXXX, where X represents any number from 0 to 9. If you try to write ordinary JavaScript code, you may need more than 50 lines. The same program can be rewritten using regular expressions, as follows: 6 of 49
7 var phonenum = "(415) "; var pattern = /^\(\d{3}\) \d{3}-\d{4}$/; document.write ("Trying to match \"" + phonenum + "\" with pattern " + pattern.tostring() + "...<br><br>"); if (pattern.test (phonenum)) {document.write ("This is a valid phone number.");} else {document.write ("This is NOT a valid phone number.");} 7 of 49
8 Understand the Regular Expressions Regular expressions in JavaScript deal with pattern matching. Other programming languages allow regular expressions to search and replace text. You can use regular expressions in JavaScript for example to: Validate telephone numbers in more than one format Extract all the numbers from a string Ensure a date is entered in the valid format Verify an address has the proper format 8 of 49
9 As we saw in the preceding code example, the regular expression pattern is quite complex, e.g.: var pattern = /^\(\d{3}\) \d{3}-\d{4}$/; Regular expressions have their own language. There are symbols and special characters to represent different things. 9 of 49
10 The following are some general rules: 1. We start with defining a variable for our regular expression pattern. var pattern; 2. The forward slash (/ ) signifies the start and end of a regular expression literal in JavaScript. Regular expression literals allow us to create a regular expression object without having to use the RegExp class. var pattern = //; 10 of 49
11 3. The caret (^) and dollar sign ($) represent the start and end of a line. They also represent the start and end of a string. If we only wanted to match the pattern to part of the string, we would omit them. Similarly, if we wanted to test specifically for a pattern at the beginning of a long string, we could just use the caret (^) by itself. The following pattern only matches an empty string ( ) : var pattern = /^$/; 11 of 49
12 4. The \d represents a single digit. If we add the \d to our pattern, it would only match a one-character string containing a number from 0 to 9. var pattern = /^\d$/; 12 of 49
13 5. If we want to match more than one number (as we do with a phone number), we can put multiple \d tokens together; \d\d\d would represent three numbers. We can also specify the number in curly braces: \d{3}. var pattern = /^\d{3}$/; 6. Other characters in the pattern, such as spaces and hyphens, represent only themselves. So the following pattern would match , which is one way to represent a telephone number. var pattern = /^\d{3}-\d{3}-\d{4}$/; 13 of 49
14 7. Since the parentheses characters have special meaning in regular expression syntax, to include them we will need to escape them with a backslash: \( and \). That gives us a pattern that matches (999) var pattern = /^\(\d{3}\) \d{3}-\d{4}$/; 14 of 49
15 There are many special tokens in the regular expression syntax to match different sets of characters. The tokens listed bellow are the basic set. \ Either denotes the start of a special token (for example, \d matches a digit) or indicates a special character is to be treated literally ( \* matches an asterisk) ^ Matches the beginning of a line; also matches the beginning of every string $ Matches the end of a line; also matches the end of every string 15 of 49
16 * A special quantifier, meaning the preceding token or group of tokens must match zero or more times + A special quantifier, meaning the preceding token or group of tokens must match one or more times? A special quantifier, meaning the preceding token or group of tokens must match zero or one time only. Matches any single character except the newline character (\n) (abcd) Matches abcd and remembers the match 16 of 49
17 car bus Matches either car or bus 17 of 49
18 {3} Matches exactly three occurrences of the preceding token or group of tokens {3,} Matches three or more occurrences of the preceding token or group of tokens {4,8} Matches four to eight occurrences of the preceding token or group of tokens 18 of 49
19 [abcdef] Matches any one of the characters a through f [a-f] Matches any one of the characters a through f [a-za-z0-9] Matches any single alphanumeric character 19 of 49
20 [^aeiou] Matches everything except a, e, i, o, and u \d Matches a digit; identical to the pattern [0-9] \D Matches a nondigit; identical to the pattern [^0-9] \s Matches a space character (there are several defined space characters) \S Matches a nonspace character 20 of 49
21 \t Matches a tab \n Matches a new line \r Matches a carriage return \w Matches any alphanumeric (word) character (a z and 0 9), including underscore ( _ ); identical to the pattern [a-za-z0-9_] \W Matches any non-word character; identical to the pattern [^a-za-z0-9_ ] 21 of 49
22 Categories of Pattern Matching Characters ^ Position matching: You wish to match a substring that occurs at a specific location within the larger string. For example, a substring that occurs at the very beginning or end of string. Only matches the beginning of a string. $ Only matches the end of a string. \b Matches any word boundary (test characters must exist at the beginning or end of a word within the string) /^The/ matches "The" in "The night" but not "In The Night" /and$/ matches "and" in "Land" but not "landing" /ly\b/ matches "ly" in "This is really cool." 22 of 49
23 \B Matches any nonword boundary. /\Bor/ matches or in "normal" but not "origami." Special literal character matching: All alphabetic and numeric characters by default match themselves literally in regular expressions. However, if you wish to match say a newline in Regular Expressions, a special syntax is needed, specifically, a backslash (\) followed by a designated character. For example, to match a newline, the syntax "\n" is used, while "\r" matches a carriage return. Alphanumeric All alphabetical and numerical characters match themselves literally. So /2 days/ will match "2 days" inside a string. \n Matches a new line character 23 of 49
24 \f Matches a form feed character \r Matches carriage return character \t Matches a horizontal tab character \v Matches a vertical tab character \xxx Matches the ASCII character expressed by the octal number xxx. "\50" matches left parentheses character "(" \xdd \uxxxx Matches the ASCII character expressed by the hex number dd. "\x28" matches left parentheses character "(" Matches the ASCII character expressed by the UNICODE xxxx. "\u00a3" matches " ". 24 of 49
25 Character classes matching: Individual characters can be combined into character classes to form more complex matches, by placing them in designated containers such as a square bracket. For example, /[abc]/ matches "a", "b", or "c", while /[a-za-z0-9]/ matches all alphanumeric characters. [xyz] Match any one character enclosed in the character set. You may use a hyphen to denote range. For example. /[az]/ matches any letter in the alphabet, /[0-9]/ any single digit. /[AN]BC/ matches "ABC" and "NBC" but not "BBC" since the leading B is not in the set. 25 of 49
26 [^xyz] Match any one character not enclosed in the character set. The caret indicates that none of the characters NOTE: the caret used within a character class is not to be confused with the caret that denotes the beginning of a string. Negation is only performed within the square brackets.. (Dot). Match any character except newline or another Unicode line terminator. /[^AN]BC/ matches "BBC" but not "ABC" or "NBC". /b.t/ matches "bat", "bit", "bet" and so on. 26 of 49
27 \w Match any alphanumeric character including the underscore. Equivalent to [a-za-z0-9_]. \W Match any single non-word character. Equivalent to [^a-za-z0-9_]. \d Match any single digit. Equivalent to [0-9]. \D Match any non-digit. Equivalent to [^0-9]. \s Match any single space character. Equivalent to [ \t\r\n\v\f]. /\w/ matches "200" in "200%" /\W/ matches "%" in "200%" /\D/ matches "No" in "No " 27 of 49
28 \S Match any single non-space character. Equivalent to [^ \t\r\n\v\f]. 28 of 49
29 Repetition matching: You wish to match character(s) that occurs in certain repetition. For example, to match "555", the easy way is to use /5{3}/ {x} Match exactly x occurrences of a regular expression. {x,} Match x or more occurrences of a regular expression. {x,y} Matches x to y number of occurrences of a regular expression.? Match zero or one occurrences. Equivalent to {0,1}. 29 of 49 /\d{5}/ matches 5 digits. /\s{2,}/ matches at least 2 whitespace characters. /\d{2,4}/ matches at least 2 but no more than 4 digits. /a\s?b/ matches "ab" or "a b".
30 * Match zero or more occurrences. Equivalent to {0,}. + Match one or more occurrences. Equivalent to {1,}. /we*/ matches "w" in "why" and "wee" in "between", but nothing in "bad" /fe+d/ matches both "fed" and "feed" 30 of 49
31 Alternation and grouping matching: You wish to group characters to be considered as a single entity or add an "OR" logic to your pattern matching. ( ) Grouping characters together to create a clause. May be nested. Alternation combines clauses into one regular expression and then matches any of the individual clauses. Similar to "OR" statement. /(abc)+(def)/ matches one or more occurrences of "abc" followed by one occurrence of "def". /(ab) (cd) (ef)/ matches "ab" or "cd" or "ef". 31 of 49
32 Back reference matching: You wish to refer back to a subexpression in the same regular expression to perform matches where one match is based on the result of an earlier match. ()\n Matches a parenthesized clause in the pattern string. n is the number of the clause to the left of the backreference. (\w+)\s+\1 matches any word that occurs twice in a row, such as "hubba hubba." The \1 denotes that the first word after the space must match the portion of the string that matched the pattern in the last set of parentheses. If there were more than one set of parentheses in the pattern string you would use \2 or \3 to match the appropriate grouping to the left of the backreference. Up to 9 backreferences can be used in a pattern string. 32 of 49
33 Pattern Switches In addition to the pattern-matching characters, you can use switches to make the match global or case- insensitive or both: Switches are added to the very end of a regular expression. i Ignore the case of characters. g Global search for all occurrences of a pattern gi Global search, ignore case. /The/i matches "the" and "The" and "the" /ain/g matches both "ain"s in "No pain no gain", instead of just the first. /it/gi matches all "it"s in "It is our IT department" 33 of 49
34 Create Patterns with a RegExp Object A regular expression literal starts and ends with a forward slash (/ ), as follows: var zipcodepattern = /^\d{5}(-\d{4})?$/; JavaScript also provides a class named RegExp to create these patterns as well. We can rewrite the pattern using this class s constructor, as follows: var zipcodepattern = new RegExp ("^\\d{5}(-\\d{4})?$"); 34 of 49
35 The backslash ( \) character needs to be escaped anytime it is included in a string, and the RegExp constructor is no exception. The double backslash ( \\) represents the escaped backslash character. 35 of 49
36 The RegExp object provides two main methods for performing its search and match functions: test() and exec(). exec () matches Searches a string for a pattern and returns all the test () Compares a string to a pattern and returns true or false based on the result 36 of 49
37 String and Regular Expression methods The String object has four methods that take regular expressions as arguments. These are your workhorse methods that allow you to match, search, and replace a string using the flexibility of regular expressions: 37 of 49
38 String Methods Using Regular Expressions Method match( regular expression ) Description Executes a search for a match within a string based on a regular expression. It returns an array of information or null if no match are found. replace( regular expression, replacement text ) Searches and replaces the regular expression portion (match) with the replaced text instead. split ( string literal or regular expression ) Breaks up a string into an array of substrings based on a regular expression or fixed string. 38 of 49
39 search ( regular expression ) Tests for a match in a string. It returns the index of the match, or 1 if not found. Does NOT support global searches (ie: "g" flag not supported). 39 of 49
40 Here are a few examples: var string1= "Peter has 8 dollars and Jane has 15" parsestring1=string1.match(/\d+/g) //returns the array [8,15] var string2="(304) " parsestring2=string2.replace (/[\(\)-]/g, "") //Returns " " (removes "(", ")", and "-") var string3="1,2, 3, 4, 5" parsestring3=string3.split (/\s*,\s*/) //Returns the array ["1","2","3","4","5"] 40 of 49
41 You can use the replace() method to modify and not simply replace a substring. This is accomplished by using the $1 $9 properties of the RegExp object. These properties are populated with the contents of the portions of the searched string that matched the portions of the search pattern contained within parentheses. 41 of 49
42 The following example illustrates how to use the replace method to swap the order of first and last names and insert a comma and a space in between them: <SCRIPT language="javascript1.2"> var objregexp = /(\w+)\s(\w+)/; var strfullname = "Jane Doe"; var strreversename = strfullname.replace(objregexp, "$2, $1"); alert(strreversename) //alerts "Doe, Jone" </SCRIPT> The output of this code will be Doe, Jane. How this works is that the pattern in the first parentheses matches Jane and this string is placed in the RegExp.$1 property. 42 of 49
43 The \s (space) character match is not saved to the RegExp object because it is not in parentheses. The pattern in the second set of parentheses matches Doe and is saved to the RegExp.$2 property. The String replace() method takes the Regular Expression object as its first argument and the replacement text as the second argument. The $2 and $1 in the replacement text are substitution variables that will substitute the contents of RegExp.$2 and RegExp.$1 in the result string. 43 of 49
44 RegExp methods and properties You just saw several regular expression related string methods; in most situations, they are all you need for your string manipulation needs. However, true to the versatility of regular expressions, the Regular Expression (RegExp) object itself also supports two methods that mimic the functions of their string counterparts, the difference being these two methods take strings as parameters, while with String functions, they take a RegExp instead. The following describes the methods and properties of the regular expression object. 44 of 49
45 Method Description test(string) Tests a string for pattern matches. This method returns a Boolean that indicates whether or not the specified pattern exists within the searched string. This is the most commonly used method for validation. It updates some of the properties of the parent RegExp object following a successful search. exec(string) Executes a search for a pattern within a string. If the pattern is not found, exec() returns a null value. If it finds one or more matches it returns an array of the match results. It also updates some of the properties of the parent RegExp object. 45 of 49
46 Here is a simple example that uses test() to see if a regular expression matches against a certain string: var pattern=/php/i pattern.test("php is your friend") //returns true 46 of 49
47 RegExp instance properties Whenever you define an instance of the regular expression (whether using the literal or constructor syntax), additional properties are exposed to this instance which you can use: Properties Property Description $n n represents a number from 1 to 9 Stores the nine most recently memorized portions of a parenthesized match pattern. For example, if the pattern used by a regular expression for the last match was /(Hello)(\s+)(world)/ and the string being searched was Hello world the contents of RegExp.$2 would be all of the space characters between Hello and world. 47 of 49
48 source Stores a copy of the regular expression pattern. global Read-only Boolean property indicating whether the regular expression has a "g" flag. ignorecase Read-only Boolean property indicating whether the regular expression has a "i" flag. lastindex Stores the beginning character position of the last successful match found in the searched string. If no match was found, the lastindex property is set to of 49
49 This simple example shows how to determine whether a regular expression has the "g" flag added: var pattern=/php/g alert(pattern.global) //alerts true 49 of 49
Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns
Perl Regular Expressions Unlike most programming languages, Perl has builtin support for matching strings using regular expressions called patterns, which are similar to the regular expressions used in
More informationAppendix. As a quick reference, here you will find all the metacharacters and their descriptions. Table A-1. Characters
Appendix As a quick reference, here you will find all the metacharacters and their descriptions. Table A-1. Characters. Any character [] One out of an inventory of characters [ˆ] One not in the inventory
More informationDr. Sarah Abraham University of Texas at Austin Computer Science Department. Regular Expressions. Elements of Graphics CS324e Spring 2017
Dr. Sarah Abraham University of Texas at Austin Computer Science Department Regular Expressions Elements of Graphics CS324e Spring 2017 What are Regular Expressions? Describe a set of strings based on
More informationThis page covers the very basics of understanding, creating and using regular expressions ('regexes') in Perl.
NAME DESCRIPTION perlrequick - Perl regular expressions quick start Perl version 5.16.2 documentation - perlrequick This page covers the very basics of understanding, creating and using regular expressions
More informationIntroduction to Regular Expressions Version 1.3. Tom Sgouros
Introduction to Regular Expressions Version 1.3 Tom Sgouros June 29, 2001 2 Contents 1 Beginning Regular Expresions 5 1.1 The Simple Version........................ 6 1.2 Difficult Characters........................
More informationUnderstanding Regular Expressions, Special Characters, and Patterns
APPENDIXA Understanding Regular Expressions, Special Characters, and Patterns This appendix describes the regular expressions, special or wildcard characters, and patterns that can be used with filters
More informationRegular Expressions Explained
Found at: http://publish.ez.no/article/articleprint/11/ Regular Expressions Explained Author: Jan Borsodi Publishing date: 30.10.2000 18:02 This article will give you an introduction to the world of regular
More informationJavaScript Functions, Objects and Array
JavaScript Functions, Objects and Array Defining a Function A definition starts with the word function. A name follows that must start with a letter or underscore, followed by any number of letters, digits,
More informationPaolo Santinelli Sistemi e Reti. Regular expressions. Regular expressions aim to facilitate the solution of text manipulation problems
aim to facilitate the solution of text manipulation problems are symbolic notations used to identify patterns in text; are supported by many command line tools; are supported by most programming languages;
More informationEssentials for Scientific Computing: Stream editing with sed and awk
Essentials for Scientific Computing: Stream editing with sed and awk Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Stream Editing sed and awk are stream processing commands. What this means is that they are
More informationHere's an example of how the method works on the string "My text" with a start value of 3 and a length value of 2:
CS 1251 Page 1 Friday Friday, October 31, 2014 10:36 AM Finding patterns in text A smaller string inside of a larger one is called a substring. You have already learned how to make substrings in the spreadsheet
More informationIndian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.
Indian Institute of Technology Kharagpur PERL Part III Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 23: PERL Part III On completion, the student will be able
More informationBioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)
Bioinformatics Programming EE, NCKU Tien-Hao Chang (Darby Chang) 1 Regular Expression 2 http://rp1.monday.vip.tw1.yahoo.net/res/gdsale/st_pic/0469/st-469571-1.jpg 3 Text patterns and matches A regular
More information3 The Building Blocks: Data Types, Literals, and Variables
chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating
More informationpsed [-an] script [file...] psed [-an] [-e script] [-f script-file] [file...]
NAME SYNOPSIS DESCRIPTION OPTIONS psed - a stream editor psed [-an] script [file...] psed [-an] [-e script] [-f script-file] [file...] s2p [-an] [-e script] [-f script-file] A stream editor reads the input
More informationCOMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual
COMS W4115 Programming Languages & Translators GIRAPHE Language Reference Manual Name UNI Dianya Jiang dj2459 Vince Pallone vgp2105 Minh Truong mt3077 Tongyun Wu tw2568 Yoki Yuan yy2738 1 Lexical Elements
More informationCSC Web Programming. Introduction to JavaScript
CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its
More informationUser Commands sed ( 1 )
NAME sed stream editor SYNOPSIS /usr/bin/sed [-n] script [file...] /usr/bin/sed [-n] [-e script]... [-f script_file]... [file...] /usr/xpg4/bin/sed [-n] script [file...] /usr/xpg4/bin/sed [-n] [-e script]...
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationsuccesses without magic London,
(\d)(?:\u0020 \u0209 \u202f \u200a){0,1}((m mm cm km V mv µv l ml C Nm A ma bar s kv Hz khz M Hz t kg g mg W kw MW Ah mah N kn obr min µm µs Pa MPa kpa hpa mbar µf db)\b) ^\t*'.+?' => ' (\d+)(,)(\d+)k
More informationRegex Guide. Complete Revolution In programming For Text Detection
Regex Guide Complete Revolution In programming For Text Detection What is Regular Expression In computing, a regular expressionis a specific pattern that provides concise and flexible means to "match"
More informationLanguage Reference Manual
TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall
More informationDecaf Language Reference Manual
Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationRegular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland
Regular Expressions Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland November 11 th, 2015 Regular expressions provide a flexible way
More informationTypescript on LLVM Language Reference Manual
Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String
More informationsed Stream Editor Checks for address match, one line at a time, and performs instruction if address matched
Week11 sed & awk sed Stream Editor Checks for address match, one line at a time, and performs instruction if address matched Prints all lines to standard output by default (suppressed by -n option) Syntax:
More informationSTREAM EDITOR - REGULAR EXPRESSIONS
STREAM EDITOR - REGULAR EXPRESSIONS http://www.tutorialspoint.com/sed/sed_regular_expressions.htm Copyright tutorialspoint.com It is the regular expressions that make SED powerful and efficient. A number
More informationPowerGREP. Manual. Version October 2005
PowerGREP Manual Version 3.2 3 October 2005 Copyright 2002 2005 Jan Goyvaerts. All rights reserved. PowerGREP and JGsoft Just Great Software are trademarks of Jan Goyvaerts i Table of Contents How to
More informationRegular Expressions in programming. CSE 307 Principles of Programming Languages Stony Brook University
Regular Expressions in programming CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 What are Regular Expressions? Formal language representing a
More informationRegex, Sed, Awk. Arindam Fadikar. December 12, 2017
Regex, Sed, Awk Arindam Fadikar December 12, 2017 Why Regex Lots of text data. twitter data (social network data) government records web scrapping many more... Regex Regular Expressions or regex or regexp
More informationRegular Expressions. Perl PCRE POSIX.NET Python Java
ModSecurity rules rely heavily on regular expressions to allow you to specify when a rule should or shouldn't match. This appendix teaches you the basics of regular expressions so that you can better make
More informationContents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual
Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9
More informationRegular Expressions. Regular Expression Syntax in Python. Achtung!
1 Regular Expressions Lab Objective: Cleaning and formatting data are fundamental problems in data science. Regular expressions are an important tool for working with text carefully and eciently, and are
More informationTCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.
http://www.tutorialspoint.com/tcl-tk/tcl_strings.htm TCL - STRINGS Copyright tutorialspoint.com The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language. These
More informationRegular Expressions Overview Suppose you needed to find a specific IPv4 address in a bunch of files? This is easy to do; you just specify the IP
Regular Expressions Overview Suppose you needed to find a specific IPv4 address in a bunch of files? This is easy to do; you just specify the IP address as a string and do a search. But, what if you didn
More informationJME Language Reference Manual
JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationPython allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:
1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,
More informationB E C Y. Reference Manual
B E C Y Tabular data manipulation language Reference Manual Authors: Bong Koh Eunchul Bae Cesar Vichdo Yongju Bang bdk2109@columbia.edu eb2263@columbia.edu cv2139@columbia.edu yb2149@columbia.edu 1 1.
More information正则表达式 Frank from https://regex101.com/
符号 英文说明 中文说明 \n Matches a newline character 新行 \r Matches a carriage return character 回车 \t Matches a tab character Tab 键 \0 Matches a null character Matches either an a, b or c character [abc] [^abc]
More informationCS 230 Programming Languages
CS 230 Programming Languages 09 / 20 / 2013 Instructor: Michael Eckmann Today s Topics Questions/comments? Continue Regular expressions Matching string basics =~ (matches) m/ / (this is the format of match
More informationAdvanced Handle Definition
Tutorial for Windows and Macintosh Advanced Handle Definition 2017 Gene Codes Corporation Gene Codes Corporation 525 Avis Drive, Ann Arbor, MI 48108 USA 1.800.497.4939 (USA) +1.734.769.7249 (elsewhere)
More informationCSC 467 Lecture 3: Regular Expressions
CSC 467 Lecture 3: Regular Expressions Recall How we build a lexer by hand o Use fgetc/mmap to read input o Use a big switch to match patterns Homework exercise static TokenKind identifier( TokenKind token
More informationJava Basic Datatypees
Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,
More informationManipulating Data in Strings and Arrays
Manipulating Data in Strings and Arrays In this chapter, you will: Manipulate strings Work with regular expressions Manipulate arrays Convert between strings and arrays Manipulating Data in Strings and
More informationConfiguring the RADIUS Listener LEG
CHAPTER 16 Revised: July 28, 2009, Introduction This module describes the configuration procedure for the RADIUS Listener LEG. The RADIUS Listener LEG is configured using the SM configuration file p3sm.cfg,
More informationPGQL 0.9 Specification
PGQL 0.9 Specification Table of Contents Table of Contents Introduction Basic Query Structure Clause Topology Constraint Repeated Variables in Multiple Topology Constraints Syntactic Sugars for Topology
More informationLearning Ruby. Regular Expressions. Get at practice page by logging on to csilm.usu.edu and selecting. PROGRAMMING LANGUAGES Regular Expressions
Learning Ruby Regular Expressions Get at practice page by logging on to csilm.usu.edu and selecting PROGRAMMING LANGUAGES Regular Expressions Regular Expressions A regular expression is a special sequence
More informationPerl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007
Perl and Python ESA 2007/2008 Eelco Schatborn eelco@os3.nl 27 September 2007 ESA: Perl Vandaag: 1. Perl introduction 2. Basic Perl: types, variables, statements,... 3. Object Oriented Perl 4. Documentation
More informationJava+- Language Reference Manual
Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect
More informationDECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.
DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special
More informationWho This Book Is For What This Book Covers How This Book Is Structured What You Need to Use This Book. Source Code
Contents Introduction Who This Book Is For What This Book Covers How This Book Is Structured What You Need to Use This Book Conventions Source Code Errata p2p.wrox.com xxi xxi xxii xxii xxiii xxiii xxiv
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationLecture Outline. COMP-421 Compiler Design. What is Lex? Lex Specification. ! Lexical Analyzer Lex. ! Lex Examples. Presented by Dr Ioanna Dionysiou
Lecture Outline COMP-421 Compiler Design! Lexical Analyzer Lex! Lex Examples Presented by Dr Ioanna Dionysiou Figures and part of the lecture notes taken from A compact guide to lex&yacc, epaperpress.com
More informationMore Examples. Lex/Flex/JLex
More Examples A FORTRAN-like real literal (which requires digits on either or both sides of a decimal point, or just a string of digits) can be defined as RealLit = (D + (λ. )) (D *. D + ) This corresponds
More informationRegular Expressions. Regular expressions match input within a line Regular expressions are very different than shell meta-characters.
ULI101 Week 09 Week Overview Regular expressions basics Literal matching.wildcard Delimiters Character classes * repetition symbol Grouping Anchoring Search Search and replace in vi Regular Expressions
More information1.1 Introduction to C Language. Department of CSE
1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to
More informationBoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)
BoredGames Language Reference Manual A Language for Board Games Brandon Kessler (bpk2107) and Kristen Wise (kew2132) 1 Table of Contents 1. Introduction... 4 2. Lexical Conventions... 4 2.A Comments...
More informationDecaf Language Reference
Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationLesson 1: Writing Your First JavaScript
JavaScript 101 1-1 Lesson 1: Writing Your First JavaScript OBJECTIVES: In this lesson you will be taught how to Use the tag Insert JavaScript code in a Web page Hide your JavaScript
More informationPIC 40A. Lecture 19: PHP Form handling, session variables and regular expressions. Copyright 2011 Jukka Virtanen UCLA 1 05/25/12
PIC 40A Lecture 19: PHP Form handling, session variables and regular expressions 05/25/12 Copyright 2011 Jukka Virtanen UCLA 1 How does a browser communicate with a program on a server? By submitting an
More information1 CS580W-01 Quiz 1 Solution
1 CS580W-01 Quiz 1 Solution Date: Wed Sep 26 2018 Max Points: 15 Important Reminder As per the course Academic Honesty Statement, cheating of any kind will minimally result in receiving an F letter grade
More informationA lexical analyzer generator for Standard ML. Version 1.6.0, October 1994
A lexical analyzer generator for Standard ML. Version 1.6.0, October 1994 Andrew W. Appel 1 James S. Mattson David R. Tarditi 2 1 Department of Computer Science, Princeton University 2 School of Computer
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationGetting to grips with Unix and the Linux family
Getting to grips with Unix and the Linux family David Chiappini, Giulio Pasqualetti, Tommaso Redaelli Torino, International Conference of Physics Students August 10, 2017 According to the booklet At this
More informationRegular Expression Reference
APPENDIXB PCRE Regular Expression Details, page B-1 Backslash, page B-2 Circumflex and Dollar, page B-7 Full Stop (Period, Dot), page B-8 Matching a Single Byte, page B-8 Square Brackets and Character
More informationRegular Expressions. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 9
Regular Expressions Computer Science and Engineering College of Engineering The Ohio State University Lecture 9 Language Definition: a set of strings Examples Activity: For each above, find (the cardinality
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationCOMP519 Web Programming Autumn A Brief Intro to Python
COMP519 Web Programming Autumn 2015 A Brief Intro to Python Python Python was created in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands.
More informationPHP and MySQL for Dynamic Web Sites. Intro Ed Crowley
PHP and MySQL for Dynamic Web Sites Intro Ed Crowley Class Preparation If you haven t already, download the sample scripts from: http://www.larryullman.com/books/phpand-mysql-for-dynamic-web-sitesvisual-quickpro-guide-4thedition/#downloads
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationegrapher Language Reference Manual
egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction
More informationX Language Definition
X Language Definition David May: November 1, 2016 The X Language X is a simple sequential programming language. It is easy to compile and an X compiler written in X is available to simplify porting between
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationLESSON 4. The DATA TYPE char
LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated
More informationUsing Lex or Flex. Prof. James L. Frankel Harvard University
Using Lex or Flex Prof. James L. Frankel Harvard University Version of 1:07 PM 26-Sep-2016 Copyright 2016, 2015 James L. Frankel. All rights reserved. Lex Regular Expressions (1 of 4) Special characters
More informationJAVASCRIPT. sarojpandey.com.np/iroz. JavaScript
JAVASCRIPT 1 Introduction JAVASCRIPT is a compact, object-based scripting language for developing client Internet applications. was designed to add interactivity to HTML pages. is a scripting language
More informationPrinciples of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
(Refer Slide Time: 00:20) Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 4 Lexical Analysis-Part-3 Welcome
More informationBashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009
Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment
More information(Refer Slide Time: 01:12)
Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl
More informationThis tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.
About the Tutorial JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. The JSON format was originally specified by Douglas Crockford,
More informationThe Logical Design of the Tokeniser
Page 1 of 21 The Logical Design of the Tokeniser Purpose 1. To split up a character string holding a RAQUEL statement expressed in linear text, into a sequence of character strings (called word tokens),
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationML 4 A Lexer for OCaml s Type System
ML 4 A Lexer for OCaml s Type System CS 421 Fall 2017 Revision 1.0 Assigned October 26, 2017 Due November 2, 2017 Extension November 4, 2017 1 Change Log 1.0 Initial Release. 2 Overview To complete this
More informationChapter 17. Fundamental Concepts Expressed in JavaScript
Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program
More informationMore Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1
More Scripting and Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 Regular Expression Summary Regular Expression Examples Shell Scripting 2 Do not confuse filename globbing
More informationExpr Language Reference
Expr Language Reference Expr language defines expressions, which are evaluated in the context of an item in some structure. This article describes the syntax of the language and the rules that govern the
More informationUniversal Format Plug-in User s Guide. Version 10g Release 3 (10.3)
Universal Format Plug-in User s Guide Version 10g Release 3 (10.3) UNIVERSAL... 3 TERMINOLOGY... 3 CREATING A UNIVERSAL FORMAT... 5 CREATING A UNIVERSAL FORMAT BASED ON AN EXISTING UNIVERSAL FORMAT...
More informationData Types and Variables in C language
Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are
More informationStructure of Programming Languages Lecture 3
Structure of Programming Languages Lecture 3 CSCI 6636 4536 Spring 2017 CSCI 6636 4536 Lecture 3... 1/25 Spring 2017 1 / 25 Outline 1 Finite Languages Deterministic Finite State Machines Lexical Analysis
More informationFILTERS USING REGULAR EXPRESSIONS grep and sed
FILTERS USING REGULAR EXPRESSIONS grep and sed We often need to search a file for a pattern, either to see the lines containing (or not containing) it or to have it replaced with something else. This chapter
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More information