Paolo Santinelli Sistemi e Reti. Regular expressions. Regular expressions aim to facilitate the solution of text manipulation problems

Size: px
Start display at page:

Download "Paolo Santinelli Sistemi e Reti. Regular expressions. Regular expressions aim to facilitate the solution of text manipulation problems"

Transcription

1 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; grep (means global regular expression print) grep searches text files for the occurrence of a specified regular expression and outputs any line containing a match to standard output. grep usage: grep [options] regex [file...] regex: regular expression ITIS E. Fermi, Modena 1 /26

2 aim to facilitate the solution of text manipulation problems Option Description i... Ignore case. Do not distinguish between upper and lower case characters. May also be specified --ignore-case. -v... Invert match. Normally, grep prints lines that contain a match. This option causes grep to print every line that does not contain a match. May also be specified --invert-match. -c... Print the number of matches (or non-matches if the -v option is also specified) instead of the lines themselves. May also be specified --count. -l... Print the name of each file that contains a match instead of the lines themselves. May also be specified --files-with-matches. -L Like the -l option, but print only the names of files that do not contain matches. May also be specified --files-withoutmatch -n... Display a prompt for input using the string prompt. Prefix each matching line with the number of the line within the file. May also be specified --line-number. ITIS E. Fermi, Modena 2 /26

3 aim to facilitate the solution of text manipulation problems Option Description h... For multi-file searches, suppress the output of filenames. May also be specified --no-filename --ignore-case. some text files to search ls /bin > dirlist-bin.txt ls /usr/bin > dirlist-usr-bin.txt ls /sbin > dirlist-sbin.txt ls /usr/sbin > dirlist-usr-sbin.txt ls dirlist*.txt dirlist-bin.txt dirlist-sbin.txt dirlist-usr-sbin.txt dirlist-usr-bin.txt ITIS E. Fermi, Modena 3 /26

4 grep simple search grep searches all of the listed files for the string bzip and finds two matches, both in the file dirlist-bin.txt: grep bzip dirlist*.txt dirlist-bin.txt:bzip2 dirlist-bin.txt:bzip2recover -l option: only the list of files that contained matches: grep -l bzip dirlist*.txt dirlist-bin.txt -L option: list of the files that did not contain a match paolo@ubuntu-server:~$ grep -L bzip dirlist*.txt dirlist-sbin.txt dirlist-usr-bin.txt dirlist-usr-sbin.txt ITIS E. Fermi, Modena 4 /26

5 Some Definitions literal: A literal is any character we use in a search or matching expression, for example, to find ind in windows the ind is a literal string - each character plays a part in the search, they form the string we want to find. metacharacter: A metacharacter is one or more special characters that have a unique meaning and are NOT used as literals in the search expression, for example, the character ^ (circumflex or caret) is a metacharacter. target string: This term describes the string that we will be searching, that is, the string in which we want to find our match or search pattern. escape sequence: An escape sequence is a way of indicating that we want to use one of our metacharacters as a literal. In a regular expression an escape sequence involves placing the metacharacter \ (backslash) in front of the metacharacter that we want to use as a literal, for example, if we want to find (s) in the target string window(s) then we use the search expression \(s\) and if we want to find \\file in the target string c:\\file then we would need to use the search expression \\\\file (each \ we want to search for as a literal (there are 2) is preceded by an escape sequence \). ITIS E. Fermi, Modena 5 /26

6 Some Definitions Metacharacter: ^ $. [ ] { } -? * + ( ) \ In addition to literals, regular expressions may also include metacharacters that are used to specify more complex matches ITIS E. Fermi, Modena 6 /26

7 the dot or period character: it is used to match any character. The Any Character If it is included it in a regular expression, it will match any character in that character position. Here s an example: paolo@ubuntu-server:~$ grep -h '.zip' dirlist*.txt bunzip2 bzip2 bzip2recover gunzip gzip funzip gpg-zip preunzip prezip prezip-bin unzip unzipsfx search for any line in files that matches the regular expression.zip, (the length of the required match is four characters). ITIS E. Fermi, Modena 7 /26

8 Anchors The caret (^) and dollar sign ($) characters are treated as anchors: they cause the match to occur only if the regular expression is found at the beginning of the line (^) or at the end of the line ($): Here there are some examples: grep -h '^zip' dirlist*.txt zip zipcloak zipgrep zipinfo zipnote Zipsplit grep -h 'zip$' dirlist*.txt gunzip gzip funzip gpg-zip preunzip prezip unzip Zip grep -h '^zip$' dirlist*.txt zip ITIS E. Fermi, Modena 8 /26

9 Bracket Expressions and Character Classes bracket expressions: match a single character from a specified set of characters; [ ] Match anything inside the square brackets for ONE character position once and only once; set of characters may contain any number of characters, and metacharacters lose their special meaning when placed within brackets; paolo@ubuntu-server:~$ grep -h '[bg]zip' dirlist*.txt bzip2 bzip2recover gzip ITIS E. Fermi, Modena 9 /26

10 Negation ^ : negates the expression; Bracket Expressions and Character Classes If the first character in a bracket expression is a caret (^), the remaining characters are taken to be a set of characters that must not be present at the given character position paolo@ubuntu-server:~$ grep -h '[^bg]zip' dirlist*.txt bunzip2 gunzip funzip gpg-zip preunzip prezip prezip-bin unzip unzipsfx ITIS E. Fermi, Modena 10 /26

11 Bracket Expressions and Character Classes Character Ranges: - (dash) inside square brackets is the 'range separator', it allows to define a range; [ ] could be rewritten as [0-9] paolo@ubuntu-server:~$ grep -h '^[ABCDEFGHIJKLMNOPQRSTUVWXZY]' dirlist*.txt paolo@ubuntu-server:~$ grep -h '^[A-Z]' dirlist*.txt MAKEDEV ControlPanel GET HEAD POST X X11 Xorg MAKEFLOPPIES NetworkManager NetworkManagerDispatcher ITIS E. Fermi, Modena 11 /26

12 Bracket Expressions and Character Classes Character Ranges: Any range of characters can be expressed this way including multiple ranges; [0-9A-C] means check for 0 to 9 and A to C matches all filenames starting with letters and numbers: paolo@ubuntu-server:~$ grep -h '^[A-Za-z0-9]' dirlist*.txt by to include a dash character in to a bracket expression, make it the first in the expression: paolo@ubuntu-server:~$ grep -h '[-AZ]' dirlist*.txt will match every filename containing a dash, or a uppercase A or an uppercase Z. ITIS E. Fermi, Modena 12 /26

13 Bracket Expressions and Character Classes POSIX Character Classes: the POSIX standard includes a number of character classes which provide useful ranges of characters Character Class Description [:alnum:]... The alphanumeric characters. In ASCII, equivalent to: [A-Za-z0-9] [:word:]... The same as [:alnum:], with the addition of the Underscore (_) character. [:alpha:]... The alphabetic characters. In ASCII, equivalent to: [A-Za-z] [:blank:]... Includes the space and tab characters [:cntrl:]... The ASCII control codes. Includes the ASCII characters 0 through 31 and 127 [:digit:]... The numerals zero through nine [:graph:]... The visible characters. In ASCII, it includes Characters 33 through 126. [:lower:]... The lowercase letters [:punct:]... The punctuation characters. In ASCII, equivalent to: [-!"#$%&'()*+,./:;<=>?@[\\\]_`{ }~] [:print:]... The printable characters. All the characters in [:graph:] plus the space character ITIS E. Fermi, Modena 13 /26

14 Bracket Expressions and Character Classes POSIX Character Classes: the POSIX standard includes a number of character classes which provide useful ranges of characters Character Class Description [:space:]... The whitespace characters including space, tab, Carriage return, newline, vertical tab, and form feed. In ASCII, equivalent to: [ \t\r\n\v\f] [:upper:]... The uppercase characters [:xdigit:]... Characters used to express hexadecimal numbers. In ASCII, equivalent to: [0-9A-Fa-f] ITIS E. Fermi, Modena 14 /26

15 Bracket Expressions and Character Classes POSIX Character Classes: the POSIX standard includes a number of character classes which provide useful ranges of characters paolo@ubuntu-server:~$ ls /usr/sbin/[[:upper:]]* /usr/sbin/makefloppies /usr/sbin/networkmanagerdispatcher /usr/sbin/networkmanager ITIS E. Fermi, Modena 15 /26

16 POSIX Basic Vs. Extended Regular Expressions POSIX splits regular expression implementations into two kinds: basic regular expressions (BRE) and extended regular expressions (ERE) POSIX regular expression basic regular expressions (BRE) extended regular expressions (ERE) BRE recognize the following metacharacters recognized: ^ $. [ ] * ( ) { } are treated as metacharacters in BRE if they are escaped with a backslash ERE recognize the following metacharacters recognized: ( ) { }? + ERE are supported by the egrep program, and grep when the -E option is used. ITIS E. Fermi, Modena 16 /26

17 Extended Regular Expressions Alternation: is the facility that allows a match to occur from among a set of expressions paolo@ubuntu-server:~$ echo "AAA" grep -E 'AAA BBB' AAA paolo@ubuntu-server:~$ echo "BBB" grep -E 'AAA BBB' BBB paolo@ubuntu-server:~$ echo "CCC" grep -E 'AAA BBB' paolo@ubuntu-server:~$ the regular expression 'AAA BBB' means match either the string AAA or the string BBB. Alternation is not limited to two choices: paolo@ubuntu-server:~$ echo "AAA" grep -E 'AAA BBB CCC' AAA ITIS E. Fermi, Modena 17 /26

18 Extended Regular Expressions Parenthesis (): is the facility that allows a match to occur from among a set of expressions To combine alternation with other regular expression elements, parenthesis () can be used to separate the alternation This expression matches the filenames that start with either bz, gz, or zip. paolo@ubuntu-server:~$ grep -Eh '^(bz gz zip)' dirlist*.txt This expression matches any filename that begins with bz or contains gz or zip paolo@ubuntu-server:~$ grep -Eh '^bz gz zip' dirlist*.txt ITIS E. Fermi, Modena 18 /26

19 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched? - Match An Element Zero Or One Time this means, Make the preceding element optional Let s say we wanted to check a phone number for validity and we considered a phone number to be valid if it matched either of these two forms: (nnn) nnn-nnnn nnn nnn-nnnn where n is a numeral. We could construct a regular expression like this: ^\(?[0-9][0-9][0-9]\)? [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$ ITIS E. Fermi, Modena 19 /26

20 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched? - Match An Element Zero Or One Time this means, Make the preceding element optional paolo@ubuntu-server:~$ echo "(555) " grep -E '^\(?[0-9][0-9][0-9] \)? [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$' (555) paolo@ubuntu-server:~$ echo " " grep -E '^\(?[0-9][0-9][0-9]\)? [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$' paolo@ubuntu-server:~$ echo "AAA " grep -E '^\(?[0-9][0-9][0-9]\)? [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$' paolo@ubuntu-server:~$ ITIS E. Fermi, Modena 20 /26

21 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched * - Match An Element Zero Or More Times it is used to denote an optional item; unlike the?, the item may occur any number of times, not just once. Let s say we wanted to see if a string was a sentence; that is, it starts with an uppercase letter, then contains any number of upper and lowercase letters and spaces, and ends with a period. we could use a regular expression like this: character classes [[:upper:]][[:upper:][:lower:] ]*\. two bracket expressions, * metacharacter, period escaped with a backslash ITIS E. Fermi, Modena 21 /26

22 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched * - Match An Element Zero Or More Times paolo@ubuntu-server:~$ echo "This works." grep -E '[[:upper:]][[:upper:][ :lower:] ]*\.' This works. paolo@ubuntu-server:~$ echo "This Works." grep -E '[[:upper:]][[:upper:][ :lower:] ]*\.' This Works. paolo@ubuntu-server:~$ echo "this does not" grep -E '[[:upper:]][[:upper: ][:lower:] ]*\.' paolo@ubuntu-server:~$ ITIS E. Fermi, Modena 22 /26

23 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched + - Match An Element One Or More Times: the + metacharacter works much like the *, except it requires at least one instance of the preceding element to cause a match. Example: regular expression that match lines consisting of groups of one or more alphabetic characters separated by single spaces: ^([[:alpha:]]+?)+$ paolo@ubuntu-server:~$ echo "This that" grep -E '^([[:alpha:]]+?)+$' This that paolo@ubuntu-server:~$ echo "a b c" grep -E '^([[:alpha:]]+?)+$' a b c paolo@ubuntu-server:~$ echo "a b 9" grep -E '^([[:alpha:]]+?)+$' paolo@ubuntu-server:~$ echo "abc d" grep -E '^([[:alpha:]]+?)+$' paolo@ubuntu-server:~$ ITIS E. Fermi, Modena 23 /26

24 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched { } - Match An Element A Specific Number Of Times the { and } metacharacters are used to express minimum and maximum numbers of required matches. They may be specified in four possible ways: Specifier Meaning {n}... Match the preceding element if it occurs exactly n times {n,m}... Match the preceding element if it occurs at least n times, but no more than m times. {n,}... Match the preceding element if it occurs n or more Times {,m}... Match the preceding element if it occurs no more than m times ITIS E. Fermi, Modena 24 /26

25 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched { } - Match An Element A Specific Number Of Times Check a phone number for validity, consider a phone number as valid if it matched either of these two forms: (nnn) nnn-nnnn or nnn nnn-nnnn, where n is a numeral. two equivalent regular expressions: ^\(?[0-9][0-9][0-9]\)? [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$ ^\(?[0-9]{3}\)? [0-9]{3}-[0-9]{4}$ ITIS E. Fermi, Modena 25 /26

26 Extended Regular Expressions Quantifiers: they are used to specify the number of times an element is matched { } - Match An Element A Specific Number Of Times Check a phone number for validity, consider a phone number as valid if it matched either of these two forms: (nnn) nnn-nnnn or nnn nnn-nnnn, where n is a numeral. paolo@ubuntu-server:~$ echo "(555) " grep -E '^\(?[0-9]{3}\)? [0-9] {3}-[0-9]{4}$' (555) paolo@ubuntu-server:~$ echo " " grep -E '^\(?[0-9]{3}\)? [0-9] {3}-[0-9]{4}$' paolo@ubuntu-server:~$ echo "AAA " grep -E '^\(?[0-9]{3}\)? [0-9] {3}-[0-9]{4}$' paolo@ubuntu-server:~$ ITIS E. Fermi, Modena 26 /26

Regular 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 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 information

STREAM EDITOR - REGULAR EXPRESSIONS

STREAM 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 information

Regex, Sed, Awk. Arindam Fadikar. December 12, 2017

Regex, 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 information

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1 Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 POSIX character classes Some Regular Expression gotchas Regular Expression Resources Assignment 3 on Regular Expressions

More information

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) 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

More information

CST Lab #5. Student Name: Student Number: Lab section:

CST Lab #5. Student Name: Student Number: Lab section: CST8177 - Lab #5 Student Name: Student Number: Lab section: Working with Regular Expressions (aka regex or RE) In-Lab Demo - List all the non-user accounts in /etc/passwd that use /sbin as their home directory.

More information

Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 4 (50 hours) Dr Antoun Yaacoub

Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 4 (50 hours) Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 4 (50 hours) Dr Antoun Yaacoub 2 Regular expressions

More information

Understanding Regular Expressions, Special Characters, and Patterns

Understanding 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 information

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

More 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 information

Module 8 Pipes, Redirection and REGEX

Module 8 Pipes, Redirection and REGEX Module 8 Pipes, Redirection and REGEX Exam Objective 3.2 Searching and Extracting Data from Files Objective Summary Piping and redirection Partial POSIX Command Line and Redirection Command Line Pipes

More information

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Bioinformatics 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 information

Pattern Matching. An Introduction to File Globs and Regular Expressions

Pattern Matching. An Introduction to File Globs and Regular Expressions Pattern Matching An Introduction to File Globs and Regular Expressions Copyright 2006 2009 Stewart Weiss The danger that lies ahead Much to your disadvantage, there are two different forms of patterns

More information

Pattern Matching. An Introduction to File Globs and Regular Expressions. Adapted from Practical Unix and Programming Hunter College

Pattern Matching. An Introduction to File Globs and Regular Expressions. Adapted from Practical Unix and Programming Hunter College Pattern Matching An Introduction to File Globs and Regular Expressions Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss The danger that lies ahead Much to your

More information

正则表达式 Frank from https://regex101.com/

正则表达式 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 information

CS Unix Tools & Scripting

CS Unix Tools & Scripting Cornell University, Spring 2014 1 February 7, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater Regular Expression A new level of mastery over your data. Pattern matching

More information

Regular Expressions Explained

Regular 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 information

Configuring the RADIUS Listener LEG

Configuring 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 information

Dr. 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 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 information

UNIX / LINUX - REGULAR EXPRESSIONS WITH SED

UNIX / LINUX - REGULAR EXPRESSIONS WITH SED UNIX / LINUX - REGULAR EXPRESSIONS WITH SED http://www.tutorialspoint.com/unix/unix-regular-expressions.htm Copyright tutorialspoint.com Advertisements In this chapter, we will discuss in detail about

More information

psed [-an] script [file...] psed [-an] [-e script] [-f script-file] [file...]

psed [-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 information

ITST Searching, Extracting & Archiving Data

ITST Searching, Extracting & Archiving Data ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the

More information

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

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 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 information

- c list The list specifies character positions.

- c list The list specifies character positions. CUT(1) BSD General Commands Manual CUT(1)... 1 PASTE(1) BSD General Commands Manual PASTE(1)... 3 UNIQ(1) BSD General Commands Manual UNIQ(1)... 5 HEAD(1) BSD General Commands Manual HEAD(1)... 7 TAIL(1)

More information

This page covers the very basics of understanding, creating and using regular expressions ('regexes') in Perl.

This 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 information

Regular 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 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 information

=~ determines to which variable the regex is applied. In its absence, $_ is used.

=~ determines to which variable the regex is applied. In its absence, $_ is used. NAME DESCRIPTION OPERATORS perlreref - Perl Regular Expressions Reference This is a quick reference to Perl's regular expressions. For full information see perlre and perlop, as well as the SEE ALSO section

More information

Regular Expressions 1

Regular Expressions 1 Regular Expressions 1 Basic Regular Expression Examples Extended Regular Expressions Extended Regular Expression Examples 2 phone number 3 digits, dash, 4 digits [[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]][[:digit:]][[:digit:]]

More information

Password Management Guidelines for Cisco UCS Passwords

Password Management Guidelines for Cisco UCS Passwords Guidelines for Cisco UCS Passwords, page 1 Guidelines for Cisco UCS Usernames, page 3 Configuring the Maximum Number of Password Changes for a Change Interval, page 4 Configuring a No Change Interval for

More information

CS160A EXERCISES-FILTERS2 Boyd

CS160A EXERCISES-FILTERS2 Boyd Exercises-Filters2 In this exercise we will practice with the Unix filters cut, and tr. We will also practice using paste, even though, strictly speaking, it is not a filter. In addition, we will expand

More information

FSASIM: A Simulator for Finite-State Automata

FSASIM: A Simulator for Finite-State Automata FSASIM: A Simulator for Finite-State Automata P. N. Hilfinger Chapter 1: Overview 1 1 Overview The fsasim program reads in a description of a finite-state recognizer (either deterministic or non-deterministic),

More information

Regular Expressions. Perl PCRE POSIX.NET Python Java

Regular 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 information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

More information

Filtering Service

Filtering Service Secure E-Mail Gateway (SEG) Service Administrative Guides Email Filtering Service Regular Expressions Overview Regular Expressions Overview AT&T Secure E-Mail Gateway customers can use Regular Expressions

More information

Regular Expressions. Regular Expression Syntax in Python. Achtung!

Regular 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 information

FILTERS USING REGULAR EXPRESSIONS grep and sed

FILTERS 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 information

Appendix. 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 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 information

Configuring the RADIUS Listener Login Event Generator

Configuring the RADIUS Listener Login Event Generator CHAPTER 19 Configuring the RADIUS Listener Login Event Generator Published: December 21, 2012 Introduction This chapter describes the configuration procedure for the RADIUS listener Login Event Generator

More information

UNIX files searching, and other interrogation techniques

UNIX files searching, and other interrogation techniques UNIX files searching, and other interrogation techniques Ways to examine the contents of files. How to find files when you don't know how their exact location. Ways of searching files for text patterns.

More information

Cisco Common Classification Policy Language

Cisco Common Classification Policy Language CHAPTER34 Cisco Common Classification Policy Language (C3PL) is a structured replacement for feature-specific configuration commands. C3PL allows you to create traffic policies based on events, conditions,

More information

Lecture 18 Regular Expressions

Lecture 18 Regular Expressions Lecture 18 Regular Expressions In this lecture Background Text processing languages Pattern searches with grep Formal Languages and regular expressions Finite State Machines Regular Expression Grammer

More information

Introduction to Regular Expressions Version 1.3. Tom Sgouros

Introduction 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 information

Regular Expressions!!

Regular Expressions!! Regular Expressions!! In your mat219_class project 1. Copy code from D2L to download regex-prac9ce.r, and run in the Console. 2. Open a blank R script and name it regex-notes. library(tidyverse) regular

More information

Regular Expression Reference

Regular 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 information

Regular Expressions. Regular expressions match input within a line Regular expressions are very different than shell meta-characters.

Regular 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 information

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture Stephen Pauwels Regular Expressions Academic Year 2018-2019 Outline What is a Regular Expression? Tools Anchors, Character sets and Modifiers Advanced Regular Expressions

More information

Structure of Programming Languages Lecture 3

Structure 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 information

Here'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:

Here'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 information

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture Regular Expressions Bart Meyers University of Antwerp August 29, 2012 Outline What? Tools Anchors, character sets and modifiers Advanced Regular expressions Exercises

More information

CSCI 2132 Software Development. Lecture 7: Wildcards and Regular Expressions

CSCI 2132 Software Development. Lecture 7: Wildcards and Regular Expressions CSCI 2132 Software Development Lecture 7: Wildcards and Regular Expressions Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 20-Sep-2017 (7) CSCI 2132 1 Previous Lecture Pipes

More information

Describing Languages with Regular Expressions

Describing Languages with Regular Expressions University of Oslo : Department of Informatics Describing Languages with Regular Expressions Jonathon Read 25 September 2012 INF4820: Algorithms for AI and NLP Outlook How can we write programs that handle

More information

Getting to grips with Unix and the Linux family

Getting 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 information

TCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.

TCL - 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 information

CSE 390a Lecture 7. Regular expressions, egrep, and sed

CSE 390a Lecture 7. Regular expressions, egrep, and sed CSE 390a Lecture 7 Regular expressions, egrep, and sed slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson http://www.cs.washington.edu/390a/ 1 2 Lecture summary regular expression

More information

User Commands sed ( 1 )

User 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 information

CS Advanced Unix Tools & Scripting

CS Advanced Unix Tools & Scripting & Scripting Spring 2011 Hussam Abu-Libdeh Today s slides are from David Slater February 25, 2011 Hussam Abu-Libdeh Today s slides are from David Slater & Scripting Random Bash Tip of the Day The more you

More information

CS 301. Lecture 05 Applications of Regular Languages. Stephen Checkoway. January 31, 2018

CS 301. Lecture 05 Applications of Regular Languages. Stephen Checkoway. January 31, 2018 CS 301 Lecture 05 Applications of Regular Languages Stephen Checkoway January 31, 2018 1 / 17 Characterizing regular languages The following four statements about the language A are equivalent The language

More information

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal Lecture 3 Tonight we dine in shell Hands-On Unix System Administration DeCal 2012-09-17 Review $1, $2,...; $@, $*, $#, $0, $? environment variables env, export $HOME, $PATH $PS1=n\[\e[0;31m\]\u\[\e[m\]@\[\e[1;34m\]\w

More information

PowerGREP. Manual. Version October 2005

PowerGREP. 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 information

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26, Part III Shell Config Compact Course @ Max-Planck, February 16-26, 2015 33 Special Directories. current directory.. parent directory ~ own home directory ~user home directory of user ~- previous directory

More information

Bashed 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 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

Fundamentals of Programming. November 19, 2017

Fundamentals of Programming. November 19, 2017 15-112 Fundamentals of Programming November 19, 2017 Today Regular Expressions Read pages 171-172 and 127-129 Background We have done several exercises where we were looking for specific patterns in a

More information

Regex Guide. Complete Revolution In programming For Text Detection

Regex 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 information

Common File System Commands

Common File System Commands Common File System Commands ls! List names of all files in current directory ls filenames! List only the named files ls -t! List in time order, most recent first ls -l! Long listing, more information.

More information

successes without magic London,

successes 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 information

6 Redirection. Standard Input, Output, And Error. 6 Redirection

6 Redirection. Standard Input, Output, And Error. 6 Redirection 6 Redirection In this lesson we are going to unleash what may be the coolest feature of the command line. It's called I/O redirection. The I/O stands for input/output and with this facility you can redirect

More information

CSE 303 Lecture 7. Regular expressions, egrep, and sed. read Linux Pocket Guide pp , 73-74, 81

CSE 303 Lecture 7. Regular expressions, egrep, and sed. read Linux Pocket Guide pp , 73-74, 81 CSE 303 Lecture 7 Regular expressions, egrep, and sed read Linux Pocket Guide pp. 66-67, 73-74, 81 slides created by Marty Stepp http://www.cs.washington.edu/303/ 1 discuss reading #2 Lecture summary regular

More information

Regular 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 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 information

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points) Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

More information

1 CS580W-01 Quiz 1 Solution

1 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 information

Computing Unit 3: Data Types

Computing Unit 3: Data Types Computing Unit 3: Data Types Kurt Hornik September 26, 2018 Character vectors String constants: enclosed in "... " (double quotes), alternatively single quotes. Slide 2 Character vectors String constants:

More information

SPEECH RECOGNITION COMMON COMMANDS

SPEECH RECOGNITION COMMON COMMANDS SPEECH RECOGNITION COMMON COMMANDS FREQUENTLY USED COMMANDS The table below shows some of the most commonly used commands in Windows Speech Recognition. The words in italics indicate that many different

More information

More regular expressions, synchronizing data, comparing files

More regular expressions, synchronizing data, comparing files More regular expressions, synchronizing data, comparing files Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Regular expressions POSIX regular expressions

More information

JFlex Regular Expressions

JFlex Regular Expressions JFlex Regular Expressions Lecture 17 Section 3.5, JFlex Manual Robb T. Koether Hampden-Sydney College Wed, Feb 25, 2015 Robb T. Koether (Hampden-Sydney College) JFlex Regular Expressions Wed, Feb 25, 2015

More information

A 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 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 information

ISO/IEC JTC1/SC22/WG20 N

ISO/IEC JTC1/SC22/WG20 N Reference number of working document: ISO/IEC JTC1/SC22/WG20 N Date: 2001-12-25 Reference number of document: ISO/IEC DTR2 14652 Committee identification: ISO/IEC JTC1/SC22 Secretariat: ANSI Information

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

Using Lex or Flex. Prof. James L. Frankel Harvard University

Using 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 information

Version November 2017

Version November 2017 Version 5.1.3 7 November 2017 Published by Just Great Software Co. Ltd. Copyright 2002 2017 Jan Goyvaerts. All rights reserved. PowerGREP and Just Great Software are trademarks of Jan Goyvaerts i Table

More information

Strings, characters and character literals

Strings, characters and character literals Strings, characters and character literals Internally, computers only manipulate bits of data; every item of data input can be represented as a number encoded in base 2. However, when it comes to processing

More information

Regexs with DFA and Parse Trees. CS230 Tutorial 11

Regexs with DFA and Parse Trees. CS230 Tutorial 11 Regexs with DFA and Parse Trees CS230 Tutorial 11 Regular Expressions (Regex) This way of representing regular languages using metacharacters. Here are some of the most important ones to know: -- OR example:

More information

Regular Expressions. Upsorn Praphamontripong. CS 1111 Introduction to Programming Spring [Ref: https://docs.python.org/3/library/re.

Regular Expressions. Upsorn Praphamontripong. CS 1111 Introduction to Programming Spring [Ref: https://docs.python.org/3/library/re. Regular Expressions Upsorn Praphamontripong CS 1111 Introduction to Programming Spring 2018 [Ref: https://docs.python.org/3/library/re.html] Overview: Regular Expressions What are regular expressions?

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Regular Expressions Primer

Regular Expressions Primer Regular Expressions Primer Jeremy Stephens Computer Systems Analyst Department of Biostatistics December 18, 2015 What are they? Regular expressions are a way to describe patterns in text. Why use them?

More information

Text & Patterns. stat 579 Heike Hofmann

Text & Patterns. stat 579 Heike Hofmann Text & Patterns stat 579 Heike Hofmann Outline Character Variables Control Codes Patterns & Matching Baby Names Data The social security agency keeps track of all baby names used in applications for social

More information

Utilities. September 8, 2015

Utilities. September 8, 2015 Utilities September 8, 2015 Useful ideas Listing files and display text and binary files Copy, move, and remove files Search, sort, print, compare files Using pipes Compression and archiving Your fellow

More information

1 Lexical Considerations

1 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 information

Today s Lecture. The Unix Shell. Unix Architecture (simplified) Lecture 3: Unix Shell, Pattern Matching, Regular Expressions

Today s Lecture. The Unix Shell. Unix Architecture (simplified) Lecture 3: Unix Shell, Pattern Matching, Regular Expressions Lecture 3: Unix Shell, Pattern Matching, Regular Expressions Today s Lecture Review Lab 0 s info on the shell Discuss pattern matching Discuss regular expressions Kenneth M. Anderson Software Methods and

More information

Regular Expressions. Steve Renals (based on original notes by Ewan Klein) ICL 12 October Outline Overview of REs REs in Python

Regular Expressions. Steve Renals (based on original notes by Ewan Klein) ICL 12 October Outline Overview of REs REs in Python Regular Expressions Steve Renals s.renals@ed.ac.uk (based on original notes by Ewan Klein) ICL 12 October 2005 Introduction Formal Background to REs Extensions of Basic REs Overview Goals: a basic idea

More information

Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

More information

Regular expressions. LING78100: Methods in Computational Linguistics I

Regular expressions. LING78100: Methods in Computational Linguistics I Regular expressions LING78100: Methods in Computational Linguistics I String methods Python strings have methods that allow us to determine whether a string: Contains another string; e.g., assert "and"

More information

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS. 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 information

UNIX II:grep, awk, sed. October 30, 2017

UNIX II:grep, awk, sed. October 30, 2017 UNIX II:grep, awk, sed October 30, 2017 File searching and manipulation In many cases, you might have a file in which you need to find specific entries (want to find each case of NaN in your datafile for

More information

The top level documentation about Perl regular expressions is found in perlre.

The top level documentation about Perl regular expressions is found in perlre. NAME DESCRIPTION perlrecharclass - Perl Regular Expression Character Classes Perl version 5.26.1 documentation - perlrecharclass The top level documentation about Perl regular expressions is found in perlre.

More information

Bash Reference Manual Reference Documentation for Bash Edition 2.5b, for Bash Version 2.05b. July 2002

Bash Reference Manual Reference Documentation for Bash Edition 2.5b, for Bash Version 2.05b. July 2002 .tex Bash Reference Manual Reference Documentation for Bash Edition 2.5b, for Bash Version 2.05b. July 2002 Chet Ramey, Case Western Reserve University Brian Fox, Free Software Foundation Copyright c 1991-2002

More information

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010 Fall 2010 Lecture 5 Hussam Abu-Libdeh based on slides by David Slater September 17, 2010 Reasons to use Unix Reason #42 to use Unix: Wizardry Mastery of Unix makes you a wizard need proof? here is the

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

CS214-AdvancedUNIX. Lecture 2 Basic commands and regular expressions. Ymir Vigfusson. CS214 p.1

CS214-AdvancedUNIX. Lecture 2 Basic commands and regular expressions. Ymir Vigfusson. CS214 p.1 CS214-AdvancedUNIX Lecture 2 Basic commands and regular expressions Ymir Vigfusson CS214 p.1 Shellexpansions Let us first consider regular expressions that arise when using the shell (shell expansions).

More information

Lexical Considerations

Lexical 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 information

Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522

Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522 Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522 Scott D. Courtney Senior Engineer, Sine Nomine Associates March 7, 2002 http://www.sinenomine.net/ Table of Contents Concepts of the Linux

More information