Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.

Slides:



Advertisements
Similar presentations
Regular Expressions in Perl By Josue Vazquez. What are Regular Expressions? A template that either matches or doesn’t match a given string. Often called.
Advertisements

Chapter 14 Perl-Compatible Regular Expressions Part 1.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
Regular Expression (1) Learning Objectives: 1. To understand the concept of regular expression 2. To learn commonly used operations involving regular expression.
COS 381 Day 19. Agenda  Assignment 5 Posted Due April 7  Exam 3 which was originally scheduled for Apr 4 is going to on April 13 XML & Perl (Chap 8-10)
PERL Part 3 1.Subroutines 2.Pattern matching and regular expressions.
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
Scripting Languages Chapter 8 More About Regular Expressions.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM to 4:00PM.
Regular Expression A regular expression is a template that either matches or doesn’t match a given string.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
Regular Expressions A regular expression defines a pattern of characters to be found in a string Regular expressions are made up of – Literal characters.
Last Updated March 2006 Slide 1 Regular Expressions.
Tutorial 14 Working with Forms and Regular Expressions.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
 Text Manipulation and Data Collection. General Programming Practice Find a string within a text Find a string ‘man’ from a ‘A successful man’
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Input Validation with Regular Expressions COEN 351.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
PHP Using Strings 1. Replacing substrings (replace certain parts of a document template; ex with client’s name etc) mixed str_replace (mixed $needle,
Regular Expressions in Perl Part I Alan Gold. Basic syntax =~ is the matching operator !~ is the negated matching operator // are the default delimiters.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
REGULAR EXPRESSIONS. Lexical Analysis Lexical analysers can be constructed by programs such as LEX These programs employ as input a description of the.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Programming Languages Meeting 13 December 2/3, 2014.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students – * Office – Wheatly.
Prof. Alfred J Bird, Ph.D., NBCT Door Code: * Office – McCormick 3rd floor 607 Office.
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
Regular Expressions.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Overview A regular expression defines a search pattern for strings. Regular expressions can be used to search, edit and manipulate text. The pattern defined.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Regular Expressions What is this line all about? while (!($search =~ /^\s*$/)) { It’s a string search just like before, but with a huge twist – regular.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
CSC 4630 Meeting 21 April 4, Return to Perl Where are we? What is confusing? What practice do you need?
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
Karthik Sangaiah.  Developed by Larry Wall ◦ “There’s more than one way to do it” ◦ “Easy things should be easy and hard things should be possible” 
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3nd floor, room 607 Office Hours –Tuesday.
ICS611 Lex Set 3. Lex and Yacc Lex is a program that generates lexical analyzers Converting the source code into the symbols (tokens) is the work of the.
Awk 2 – more awk. AWK INVOCATION AND OPERATION the "-F" option allows changing Awk's "field separator" character. Awk regards each line of input data.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Computer Science I Split. Regular Expressions Classwork: Trivia questions. Share. Show (stage 1) final project. Homework: work on final project.
Regular Expressions.
IT441 Network Services Administration
IT441 Network Services Administration
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
CIT 383: Administrative Scripting
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students – * Office – Wheatly 2nd floor Office Hours – MW 3:00PM to 4:00PM

 What if I wanted to find a pattern only at the start of a line or at the end of a line?  In a Regex we can use anchors.  To indicate the pattern must be at the start of a line we use the ^  i.e. /^The/  To indicate the pattern must be at the end of the line we use the anchor $  i.e./end$/

 We can make our Regex more general by using metacharacters.  See the table on page 167 in the text  Four of the more common metacharacters are: .Matches any character except newline  ? Preceding character or group may be present 0 or 1 time  +Preceding character or group is present 1 or more times  *Preceding character or group may be present 0 or more times

 What does the metacharacter. do?  It matches any single character!  So give some examples of what /Bet.y/ would match?  What does the metacharacter * do?  It matches if the preceding character or group may be present 0 or more times  So give some examples of what /Bet*y/ would match

 What will happen if we combine these two metacharcaters?  What will the Regex /fred.*barney/ match?  How about the Regex /.*/?  How about if we wanted to find the string ?  What would this Regex match?  / /

 How about if we wanted to find the string ?  What would this Regex match?  / / (remember the. is a metacharcater)  So we need to “Escape” it just like we do in a double quoted string  /3\.14159/ will work  If we want to use any metacharacter to represent itself we need to “Escape” it using the \

 What does the metacharcater + do?  It matches if the preceding character or group is present 1 or more times  What string will the following Regex match?  /cat/  What about?  /cat+/  Or?  /(cat)+/

 What if we want a choice in out Regex?  We can use the logical or.  We want to find out if either the name fred or barbey is in the text. We would write the regex:  /fred|barney/

 We can include groups of characters in a Regex  [0-9] will match any number  [a-z] will match any lower case letter  [A-Z] will match any upper case letter  How about [a-zA-z]?  There are shortcuts for these classes  /d represents [0-9] a digit  /D represents [^0-9] a non-digit  There are others as we will see on page 167

 So far we have been matching against the default $_. What if we want to match against another variable?  We need to use the “Binding” operator =~  if ($someOther =~ /fred/) { action}  This will perform the action if the match is true

 Remember last class we used the split() function to break the string up into substrings separated by whitespace.  We can use any arbitrary character to split the string.  For example = split /,/ $stringGettysburg will split the gettysburg file into phrases separated by commas and store each phrase in a separate entry in the  Write a program to try this.

 Write a program that:  Reads the passwd file.  (I hope you remember where it is)  Breaks each record into its components  Do you remember what they are?? I hope so!!  Then checks to see if you have an account on this machine

 Write a program that  Reads the gettsyburg file into a string variable  Breaks the file up into individual words  Uses the array sort() function to arrange the words in alphabetical order  Calculates the number of times each individual word appears in the address

 Read pages 153 to 177 in the textbook.  Try and complete exercise #3 on page 177