CompSci 101 Introduction to Computer Science April 7, 2015 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.
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.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Computer Science 101 Introduction to Programming.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Python Regular Expressions Easy text processing. Regular Expression  A way of identifying certain String patterns  Formally, a RE is:  a letter or.
1 CSC 594 Topics in AI – Text Mining and Analytics Fall 2015/16 4. Document Search and Regular Expressions.
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.
What is a language? An alphabet is a well defined set of characters. The character ∑ is typically used to represent an alphabet. A string : a finite.
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)
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Regular Expressions Regular Expressions. Regular Expressions  Regular expressions are a powerful string manipulation tool  All modern languages have.
Regular Expression What is Regex? Meta characters Pattern matching Functions in re module Usage of regex object String substitution.
©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.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
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)
REGULAR EXPRESSIONS 4 DAY 9 - 9/15/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
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.
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 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 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
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.
Regular Expressions Upsorn Praphamontripong CS 1110
CompSci 101 Introduction to Computer Science
Introduction to Python
System Administration Introduction to Scripting, Perl Session 5 – Fri 23 Nov 2007 References: Perl man pages Albert Lingelbach, Jr.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction To Python
Introduction to Computer Science
CS 1111 Introduction to Programming Fall 2018
1.5 Regular Expressions (REs)
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger

Announcements No reading for next class, No RQ Assignment 7 due Thursday APT 9 out, due next Tuesday Do not discuss exam until it is handed back.

Snarky Hangman 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 r for raw string - r’a phrase’

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

Regular Exp – match and group phrase = "bogus 75 a test" match = phrase) if match: print match.group() match = phrase) if match: print match.group() print match.group(1) print match.group(2)

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 fruit = sorted(fruit,key=operator.itemgetter(1)) fruit.sort(key=operator.itemgetter(0), reverse=True)