CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.

Slides:



Advertisements
Similar presentations
Regular Expressions Pattern and Match objects Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein.
Advertisements

Lex -- a Lexical Analyzer Generator (by M.E. Lesk and Eric. Schmidt) –Given tokens specified as regular expressions, Lex automatically generates a routine.
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
CompSci 101 Introduction to Computer Science Feb 26, 2015 Prof. Rodger.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
Introduction to Python
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
Scripting Languages Chapter 8 More About Regular Expressions.
Working with Files CSC 161: The Art of Programming Prof. Henry Kautz 11/9/2009.
Regex Wildcards on steroids. Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
Programming for Linguists An Introduction to Python 24/11/2011.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Finding the needle(s) in the textual haystack
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Review: Regular expression: –How do we define it? Given an alphabet, Base case: – is a regular expression that denote { }, the set that contains the empty.
Python Regular Expressions Easy text processing. Regular Expression  A way of identifying certain String patterns  Formally, a RE is:  a letter or.
Copyright © 2009 Lumina Decision Systems, Inc. Regular Expressions in Analytica 4.2 Lonnie Chrisman Lumina Decision Systems Analytica User Group 9 July.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.
 2003 Jeremy D. Frens. All Rights Reserved. Calvin CollegeDept of Computer Science(1/8) Regular Expressions in Java Joel Adams and Jeremy Frens Calvin.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Regular Expressions for PHP Adding magic to your programming. Geoffrey Dunn
©Brooks/Cole, 2001 Chapter 9 Regular Expressions.
GREP. Whats Grep? Grep is a popular unix program that supports a special programming language for doing regular expressions The grammar in use for software.
CompSci 6 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
Perl Day 4. Fuzzy Matches We know about eq and ne, but they only match things exactly We know about eq and ne, but they only match things exactly –Sometimes.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
Java Script Pattern Matching Using Regular Expressions.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Regular expressions Day 11 LING Computational Linguistics Harry Howard Tulane University.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
Pattern Matching: Simple Patterns. Introduction Programmers often need to scan a file, directory, etc. for a specific substring. –Find all files that.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
Finding the needle(s) in the textual haystack
Regular Expressions Upsorn Praphamontripong CS 1110
CompSci 101 Introduction to Computer Science
System Administration Introduction to Scripting, Perl Session 5 – Fri 23 Nov 2007 References: Perl man pages Albert Lingelbach, Jr.
Perl-Compatible Regular Expressions Part 1
Finding the needle(s) in the textual haystack
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Finding the needle(s) in the textual haystack
Introduction to Computer Science
CS 3304 Comparative Languages
CSE 1020:Software Development
CS 1111 Introduction to Programming Fall 2018
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
PHP –Regular Expressions
Presentation transcript:

CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger

Announcements Reading for next time on calendar page –RQ maybe Assignment 7 due Thursday APT 9 is out today Do not discuss exam until it is handed back

Snarky Hangman Demo Dictionary of categories Start with list of words of correct size Repeat –User picks a letter –Make dictionary of categories based on letter –New list of words is largest category Matched letters Letters guessed by not chosen List shrinks in size each time

Regular Expressions Powerful language for matching text patterns Part of the compiler process –Can write a regular expression for each type of word in a programming language –Example Key words – if, else, elif, while Integers – 456, 78, 2, -56 Float – 3.14, String – ‘word’, “this is a phrase” Special symbols – [ ] + %

Regular Expressions a- a a* - a repeated 0 or more times a+ - a repeated 1 or more times a? – a 0 or 1 time, so a is optional ^ - match at the beginning of the string $ - match at the end of the string. – matches anything [abc] – match a, b, or c [a-z] – match any character from a to z [^a] – match any character but a

More on regular expressions | - or \b - word boundary \s - whitespace character \d – match any digit When using backslashes – must use r in front of string

Regular expressions with re import re re.sub(pattern, repl, str) – return string that replaces the pattern matches with repl in string str – looks from left end of string re.compile() – create a pattern re.findall() See code examples

More on sort Import operator –fruit = [(“pear”,5),(“apple”,9)] fruit = sorted(fruit) fruit.sort() OR fruit = sorted(fruit) –arguments key=itemgetter(0) reverse=True