Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland

Size: px
Start display at page:

Download "Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland"

Transcription

1 Regular Expressions Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland November 11 th, 2015

2 Regular expressions provide a flexible way to identify and subsequently manipulate strings of text of interest, such as words or any patterns of characters. For example: the sequence of characters "car" in any context, such as "car", "cartoon", or "bicarbonate" the word "car" when it appears as an isolated word the word "car" when preceded by the word "blue" or "red" a dollar sign immediately followed by one or more digits, and then optionally a period and exactly two more digits a URL or an address ( (<name>@<text>.<text>) Find eg all AGI codes in a given text which would look like At<digit>g<five digits> Find duplicated words in a text

3 Regular expressions, or regexes, provide a very very powerful tool to search and manipulate huge amounts of data (text, databases, output of commands) very efficiently. Many programming languages have implementations of regular expressions. The Perl implementation of regular expressions is built into the core of the language, other languages use add-on packages for regex support. Unix has several tools that use regular expressions. Most notably the scripting language Awk (not featured in this lecture) and the tool grep (more powerful in the egrep Implementation).

4 REGular EXpressions are a way of thinking!

5 Egrep Metacharacters Metacharacters are special markers that ensure the desired results when combined with other characters. Without metacharacters it is very difficult or impossible to build efficient regular expressions and a search essentially becomes a simple plain text search. In a search for the word cat a plain text search also finds the result vacation. In egrep (and Perl) the metacharacters for start of line and end of line are the ^ (caret) and $ (dollar sign). The search ^cat returns only the lines where cat is right in the beginning of a line wheras cat$ returns only those, where cat is in the end (like scat).

6 Egrep Metacharacters What would the following expressions find: ^cat$ ^$ ^

7 Egrep Metacharacters What would the following expressions find: ^cat$ Matches if the line has a beginning (which all lines have)followed immediately by cat, then followed immediately by the end of the line (which all lines should have) ^$ Matches if the line has a beginning, followed immediately by the end of the line. Finds empty lines. ^ Means to match if the line has a beginning (which every line has). It matches empty and non-empty lines and essentially achieves nothing.

8 Egrep Character Classes spelled gray. grey but you want to find it also when Instead of doing to independent searches you can use the character class. construct to create a gr[ea]y Will find a g, followed by r, followed by either e or a finally followed by a y.

9 Egrep Character Classes The character class can contain as many characters as you like. To search for a particular locus on all Arabidopsis chromosomes you can use a character class: At[12345]g09970

10 Egrep Character Classes Multiple ranges are fine. You could define something like this: [abcdefabcdef ] This is awkward to write, so it is better to use a shorthand for this: [a-fa-f0-6] The following class [0-9A-Z_!.?] Will match digits, uppercase letters, underscore, exclamation mark, period and question mark.

11 Egrep Character Classes Note: The dash is something special. In a character class it usually indicates a range of characters (A-Z). Outside a character class it matches the normal dash. However, if interpreted as a plain character.

12 Egrep Character Classes You can also use negated character classes if you use instead of. For example [^1-6] matches a character that is not 1, 2, 3, 4, 5 or 6. The caret is the same, that has been introduced before as an anchor for the beginning of a line.

13 Egrep Character Classes Iraqi Iraqian miqra qasida qintar qoph zaqqum Words not found but included were: Qantas or Iraq. WHY???

14 Egrep Character Classes (Overview) Character classes in egrep:. stands for every character except newline. [a-z] uses all characters from a to z (in lowercase use [A-Z] for uppercase) [0-9] uses all digits \w Alphanumeric characters [A-Za-z0-9_] [:alnum:] Alphanumeric characters. [:alpha:] Alphabetic characters. [:blank:] Space and TAB characters. [:cntrl:] Control characters. [:digit:] Numeric characters. [:graph:] Characters that are both printable and visible. (A space is printable but not visible, whereas an `a' is both.) [:lower:] Lowercase alphabetic characters. [:print:] Printable characters (characters that are not control characters). [:punct:] Punctuation characters (characters that are not letters, digits, control or space characters). [:space:] Space characters (such as space, TAB, and formfeed, to name a few). [:upper:] Uppercase alphabetic characters. [:xdigit:] Characters that are hexadecimal digits. While egrep can use negated classes, the v option is an often more convenient way to find everything except the defined class.

15 Alternation Looking back we used the following construct to search for grey and gray: gr[ea]y This can also be written using alternation instead of a character class: gr(e a)y The parenthesis is required because the search term gre ay would results in either gre or ay, which is clearly not what is wanted here.

16 Alternation The following alternations result in the same outcome: Jeffrey Jeffery Jeff(rey ery) Jeff(re er)y To have them match the spelling Geoffrey or Geoffery we can modify it further: (Geoff Jeff)(rey ery) (Geo Je)ff(rey ery) (Geo je)ff(re er)y All of those match the longer (but simpler) Jeffrey Jeffery Geoffrey Geoffery

17 Ignoring Differences in Capitalization To make your regex case insensitive you can specify the i option in egrep (in Perl and most other programming languages use the i modifier for your regex).

18 Word Boundaries To avoid finding occurences of your word embedded in a bigger word you can use the word boundaries to avoid those results. In grep you can use the a little odd looking \< and \> metasequences to specify that. The expression \<cat\> literally means match if we can find a start of word position, followed immediately by c, a and t, followed immediately by an end of word position. word boundary metasequences from the combination with the backslash \

19 Metacharacter Name Matches. dot any one character character class any character listed negated character class any character not listed ^ caret position at the start of line $ dollar position at the end of line \< backslash less than position at start of word \> backslash greater than position at end of word or, bar, pipe matches either expression it separates parentheses used to limit scope of, plus additional uses (discussed later)

20 Quantifiers With quantifiers we are able to specify how many instances of A certain character or character class we want to match. Quantifiers can be separated into greedy and non-greedy. Greedy quantifiers will match everything they can while nongreedy ones will only match until a given criterium is matched for the first time. Greedy quantifiers:? * + {n} {m,n} Matches n instances Matches at least m but at most n instances, matches the maximum possible

21 Quantifiers Search for color and colour: colou?r July or abbreviation Jul: July? You can use the parentheses to group characters in order to apply a quantifier to the group: 4(th)? will find 4 but also 4th

22 Parentheses and Backreferences So far we have used the parentheses to limit the scope of alternation or to group multiple characters into larger units to which you can apply quantifiers. matched by the subexpression they enclose. This can used to solve the problem of finding doubled words for example. \<the +the\> finds word boundary, the followed immediately by at least one whitespace and then the and a word boundary. To make this work also for other words we can modify it like this: \<([a-za-z]+) +\1\> The \1 (backslash 1) is a backreference pointing to the text in the parentheses.

23 The Great Escape So how can you use a character that is usually a meta character as an actual character??? You use the backslash to escape them. The. (period) usually matches any character except newline. To match an actual. you escape it: \. To use an actual \ (backslash) you also escape it: \\

24 Some egrep examples egrep can use the output of any Unix command: ls /usr egrep ls /usr egrep ls /usr egrep l b ls /usr egrep ls /usr egrep egrep however, can also search files directly: egrep filename Modifiers for egrep: -i case-insensitive -v everything but the matches AGI code examples: egrep i agi.txt egrep iv agi.txt

25 How Does Pattern Matching Work? (NFA and DFA) Both regex engines follow 2 rules: 1.The match that begins earliest (leftmost) wins. 2. The standard quantifiers (*, +,? and {m,n} are greedy.

26 1. Earliest Match Wins Rule This rule says, that any match that begins earlier in the string is always preferred over any plausible match that begins later. The match is first attempted at the very beginning of the string to be searched the entire (perhaps complex) regex is tested starting right at that spot. If all possibilities are exhausted and a match is not found, the complete expression is re-tried starting from just before the second character. This full retry occurs at each position in the string until a match is found. No match is reported only after the full retry has been attempted at each position all the way to the end of the string (after the last character).

27 1. Earliest Match Wins Rule The second attempt also fails (ORA does not match LOR either). The attempt starting at the third position however matches, so the engine stops and reports the match. FLORAL.

28 1. Why Is This Rule Important? The dragging belly indicates your cat is too fat. Is you search for indicates appears earlier in the string. This is not important in cases like grep, where you just test for the presence of a string, but if you search AND replace the distinction becomes paramount. Where will this match in the example above: fat cat belly your

29 2. The Standard Quantifiers Are Greedy Greedy means, that the quantifiers will match as many characters as possible. They will settle for something else than the maximum if they have to, but the always attempt to match as many times as then can up to the absolute maximum allowed. The only time they settle for anything less than their allowed maximum is when matching too much ends up causing some later part of the regex to fail. Example: \b\w+s\b The \w+ happily matches the whole word, but if it did, there would be nothing for the s to match. For the match to succeed, \w+ s\b to be able to match.

30 2. Greedy Quantifiers: First Come, First Served What is being captured by the parentheses in this example: 2003 Regex: ^.*([0-9]+) WHY???

31 Where to go from here? Regular expressions are a quite complicated topic, we barely scratched the surface here. We did not address different types of regex engines and we also did not touch the topic of the performance and efficiency of regular expressions. Suggested further reading: Mastering Regular Expressions THE regex bible! Covers almost every aspect of regular expressions. Regular Expressions Pocket Reference A quick and good reference to regexes in most Unix tools and scripting languages. Requires however understanding of regular expressions. Michael Wrzaczek, michael.wrzaczek@helsinki.fi

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

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

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

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

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

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

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

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

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

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

Lecture 2. Regular Expression Parsing Awk

Lecture 2. Regular Expression Parsing Awk Lecture 2 Regular Expression Parsing Awk Shell Quoting Shell Globing: file* and file? ls file\* (the backslash key escapes wildcards) Shell Special Characters ~ Home directory ` backtick (command substitution)

More information

Essentials for Scientific Computing: Stream editing with sed and awk

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

Table ofcontents. Preface. 1: Introduction to Regular Expressions xv

Table ofcontents. Preface. 1: Introduction to Regular Expressions xv Preface... xv 1: Introduction to Regular Expressions... 1 Solving Real Problems.. 2 Regular Expressions as a Language.. 4 The Filename Analogy.. 4 The Language Analogy 5 The Regular-Expression Frame of

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

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

=~ 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 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

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

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

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

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

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

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

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

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

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

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

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

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

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

The Little Regular Expressionist

The Little Regular Expressionist The Little Regular Expressionist Vilja Hulden August 2016 v0.1b CC-BY-SA 4.0 This little pamphlet, which is inspired by The Little Schemer by Daniel Friedman and Matthias Felleisen, aims to serve as a

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

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

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

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

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

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

Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

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

Introduction to regular expressions

Introduction to regular expressions Introduction to regular expressions Table of Contents Introduction to regular expressions Here's how we do it Iteration 1: skill level > Wollowitz Iteration 2: skill level > Rakesh Introduction to regular

More information

Regular Expressions for Technical Writers (tutorial)

Regular Expressions for Technical Writers (tutorial) Regular Expressions for Technical Writers (tutorial) tcworld conference 2016 - Stuttgart, Germany Scott Prentice, Leximation, Inc. modified 2017-05-13 (fixed typos) Introduction Scott Prentice, President

More information

Wildcards and Regular Expressions

Wildcards and Regular Expressions CSCI 2132: Software Development Wildcards and Regular Expressions Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Searching Problem: Find all files whose names match a certain

More information

IT441. Regular Expressions. Handling Text: DRAFT. Network Services Administration

IT441. Regular Expressions. Handling Text: DRAFT. Network Services Administration IT441 Network Services Administration Handling Text: DRAFT Regular Expressions Searching for Text in a File Make note of the following directory: /home/ckelly/course_files/it441_files Given the file gettysburg.txt

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

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

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

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

Effective Programming Practices for Economists. 17. Regular Expressions

Effective Programming Practices for Economists. 17. Regular Expressions Effective Programming Practices for Economists 17. Regular Expressions Hans-Martin von Gaudecker Department of Economics, Universität Bonn Motivation Replace all occurences of my name in the project template

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

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

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

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

Beginning Perl for Bioinformatics. Steven Nevers Bioinformatics Research Group Brigham Young University

Beginning Perl for Bioinformatics. Steven Nevers Bioinformatics Research Group Brigham Young University Beginning Perl for Bioinformatics Steven Nevers Bioinformatics Research Group Brigham Young University Why Use Perl? Interpreted language (quick to program) Easy to learn compared to most languages Designed

More information

https://lambda.mines.edu You should have researched one of these topics on the LGA: Reference Couting Smart Pointers Valgrind Explain to your group! Regular expression languages describe a search pattern

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

Regular Expressions for Technical Writers

Regular Expressions for Technical Writers Regular Expressions for Technical Writers STC Summit 2017 - Washington DC Scott Prentice, Leximation, Inc. Introduction Scott Prentice, President of Leximation, Inc. Specializing in FrameMaker plugin development

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

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

- 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

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

LESSON 4. The DATA TYPE char

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

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

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

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns

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

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

ML 4 A Lexer for OCaml s Type System

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

Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011

Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011 Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011 Last time Compiling software and the three-step procedure (./configure && make && make install). Dependency hell and

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

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

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

Version June 2017

Version June 2017 Version 2.7.0 19 June 2017 Published by Just Great Software Co. Ltd. Copyright 2009 2017 Jan Goyvaerts. All rights reserved. RegexMagic and Just Great Software are trademarks of Jan Goyvaerts i Table of

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

Awk & Regular Expressions

Awk & Regular Expressions Awk & Regular Expressions CSCI-620 Dr. Bill Mihajlovic awk Text Editor awk, named after its developers Aho, Weinberger, and Kernighan. awk is UNIX utility. The awk command uses awk program to scan text

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

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

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

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

Digital Humanities. Tutorial Regular Expressions. March 10, 2014

Digital Humanities. Tutorial Regular Expressions. March 10, 2014 Digital Humanities Tutorial Regular Expressions March 10, 2014 1 Introduction In this tutorial we will look at a powerful technique, called regular expressions, to search for specific patterns in corpora.

More information

Additional Resources

Additional Resources APPENDIX Additional Resources This appendix points out the rather short list of online and other resources available for further assistance with mod_rewrite. Online Resources Online resources for mod_rewrite

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

Object-Oriented Software Engineering CS288

Object-Oriented Software Engineering CS288 Object-Oriented Software Engineering CS288 1 Regular Expressions Contents Material for this lecture is based on the Java tutorial from Sun Microsystems: http://java.sun.com/docs/books/tutorial/essential/regex/index.html

More information

5/8/2012. Exploring Utilities Chapter 5

5/8/2012. Exploring Utilities Chapter 5 Exploring Utilities Chapter 5 Examining the contents of files. Working with the cut and paste feature. Formatting output with the column utility. Searching for lines containing a target string with grep.

More information

Shell Programming Overview

Shell Programming Overview Overview Shell programming is a way of taking several command line instructions that you would use in a Unix command prompt and incorporating them into one program. There are many versions of Unix. Some

More information

CS 230 Programming Languages

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

Expr Language Reference

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

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

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

Basics. I think that the later is better.

Basics.  I think that the later is better. Basics Before we take up shell scripting, let s review some of the basic features and syntax of the shell, specifically the major shells in the sh lineage. Command Editing If you like vi, put your shell

More information

CSCI 2132 Software Development. Lecture 8: Introduction to C

CSCI 2132 Software Development. Lecture 8: Introduction to C CSCI 2132 Software Development Lecture 8: Introduction to C Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 21-Sep-2018 (8) CSCI 2132 1 Previous Lecture Filename substitution

More information

CS 2112 Lab: Regular Expressions

CS 2112 Lab: Regular Expressions October 10, 2012 Regex Overview Regular Expressions, also known as regex or regexps are a common scheme for pattern matching regex supports matching individual characters as well as categories and ranges

More information

Advanced Handle Definition

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

The Java Language Rules And Tools 3

The Java Language Rules And Tools 3 The Java Language Rules And Tools 3 Course Map This module presents the language and syntax rules of the Java programming language. You will learn more about the structure of the Java program, how to insert

More information

Motivation (Scenarios) Topic 4: Grep, Find & Sed. Displaying File Names. grep

Motivation (Scenarios) Topic 4: Grep, Find & Sed. Displaying File Names. grep Topic 4: Grep, Find & Sed grep: a tool for searching for strings within files find: a tool for examining a directory tree sed: a tool for "batch editing" Associated topic: regular expressions Motivation

More information