Nate Brunelle Today: Regular Expressions

Slides:



Advertisements
Similar presentations
Regular Expressions BKF03 Brian Ciccolo. Agenda Definition Uses – within Aspen and beyond Matching Replacing.
Advertisements

Python regular expressions. “Some people, when confronted with a problem, think ‘I know, I'll use regular expressions.’ Now they have two problems.”
Lex -- a Lexical Analyzer Generator (by M.E. Lesk and Eric. Schmidt) –Given tokens specified as regular expressions, Lex automatically generates a routine.
Regular Expressions (in Python). Python or Egrep We will use Python. In some scripting languages you can call the command “grep” or “egrep” egrep pattern.
Python: Regular Expressions
Regular Expression ASCII Converting. Regular Expression Regular Expression is a tool to check if a string matches some rules. It is a very complicated.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
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.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Corpus Linguistics- Practical utilities (Lecture 7) Albert Gatt.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
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. Overview Regular expressions allow you to do complex searches within text documents. Examples: Search 8-K filings for restatements.
Python for NLP Regular Expressions CS1573: AI Application Development, Spring 2003 (modified from Steven Bird’s notes)
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CS355 - Theory of Computation Regular Expressions.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Michael Kovalchik CS 265, Fall  Parenthesis group parts of expressions together  “/CS265|CS270/” => “/CS(265|270)/”  Groups can be nested  “/Perl|Pearl/”
Regular expressions Day 11 LING Computational Linguistics Harry Howard Tulane University.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
Deterministic Finite Automata Nondeterministic Finite Automata.
Chapter 18 The HTML Tag
Regular Expressions.
RE Tutorial.
Finding the needle(s) in the textual haystack
Regular Expressions Upsorn Praphamontripong CS 1110
Regular Expressions 'RegEx'.
Theory of Computation Lecture #
Strings and Serialization
Looking for Patterns - Finding them with Regular Expressions
/208/.
Lecture 19 Strings and Regular Expressions
CSC 594 Topics in AI – Natural Language Processing
COMP 170 – Introduction to Object Oriented Programming
Chapter 2 Scanning – Part 1 June 10, 2018 Prof. Abdelaziz Khamis.
Lecture 9 Shell Programming – Command substitution
Finding the needle(s) in the textual haystack
Finding the needle(s) in the textual haystack
CSC 594 Topics in AI – Natural Language Processing
Pattern Matching in Strings
Topics in Linguistics ENG 331
LING 388: Computers and Language
Advanced Find and Replace with Regular Expressions
i206: Lecture 19: Regular Expressions, cont.
Nate Brunelle Today: Functions again, Scope
CS 1111 Introduction to Programming Fall 2018
Nate Brunelle Today: Regular Expressions
Nate Brunelle Today: Strings, Type Casting
Regular Expressions and Grep
Nate Brunelle Today: Conditional Decision Statements
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Lecture 25: Regular Expressions
1.5 Regular Expressions (REs)
Recursion as a Problem-Solving Technique
Regular Expressions in Java
Regular Expressions in Java
Regular Expression in Java 101
Nate Brunelle Today: Regular Expressions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Regular Expressions
Nate Brunelle Today: Regular Expressions
REGEX.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
Regular Expressions in Java
Regular Expressions.
Presentation transcript:

Nate Brunelle Today: Regular Expressions CS1110 Nate Brunelle Today: Regular Expressions

Questions?

String.find() Takes a string as an argument, and if exactly that string appears, give its index Mystring.find(“Purple Elephant”) “purple elephant”.find(“Purple Elephant”) “the elephant was purple”

Wildcards [Rr]ugs?[^a-zA-Z] Match on/ find: Will not match on/find: Rugged rugged We might want: A way of saying r or R å Maybe there’s an s ç Something that’s not a letter ê åugçê [Rr]ugs?[^a-zA-Z]

R string “\”” r“\”this” -> error r“\n” -> \n

Regex Pieces Operation Example Meaning Character class [Rr] or [rR] [abcd] [\^] R or r Exactly one of a, b, c, or d Just carat (^) Character Range [a-z] [a-zA-Z] [0-9] Exactly one character “between” a and z “between” a and z or “between” A and Z Any one digit Negative character class [^a] [^a-zA-Z] [^\^] Any one character that’s not an a Any one character that’s not a letter any one character that’s not a carat Optional Quantifier s? [Rr]? Maybe there’s an s, 0 or 1 s Either have one of R or r or neither OR wx|xyz One of the strings wx or xyz Star [abc]* Any number of a’s b’s and c’s at all Plus [abc]+ At least one of a’s, b’s, and c’s

Regex Pieces, Cont. Operation Example Meaning

[Rr]? ‘’ R r (yz | xyz)?

Give an Expression to match All UVA computing IDs 2-3 letters, number, 1-3 letters [a-z] [a-z] [a-z]?[1-9] [a-z] [a-z]? [a-z]?

Give strings which match: [Dr]oc[^0-9][3-5!] rock! DocǓ4 [3-5!] A character (between 3 and 5) or !

Something we can’t do with [], *, +, ? His or hers Hi?e?r?s His|hers H (i|er) s

Give strings which match: fl[ou]*r? fl flour floor flu flo floo flououou flooooooooooooor floouuuouuuuuuuuuo flur flr Fl[ou]*r Flr | fl[ou]r | fl[ou][ou]r …

Give an Expression to match 3 words separated by spaces [a-z]* [a-z]* [a-z]* The box [a-z]+ [a-z]+ [a-z]+

Give an Expression to match nate and brunelle within 3 words of one another nate man myth legend brunelle nate the rock brunelle Nate brunelle nate ([a-z]+ )?([a-z]+ )?([a-z]+ )?brunelle

In python import re Compile Operate Match Object search finditer Similar to string.find() finditer Findall 0 parentheses: m.group() 1 paren: m.group(1) 2+ paren: m.groups() Match Object group start end groups