Regex Wildcards on steroids. Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the.

Slides:



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

AND FINITE AUTOMATA… Ruby Regular Expressions. Why Learn Regular Expressions? RegEx are part of many programmer’s tools  vi, grep, PHP, Perl They provide.
Data Manipulation & Regular Expressions CSCI 215.
1 CSE 390a Lecture 7 Regular expressions, egrep, and sed slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
1 CSE 303 Lecture 7 Regular expressions, egrep, and sed read Linux Pocket Guide pp , 73-74, 81 slides created by Marty Stepp
Regular Expressions in Java. Namespace in XML Transparency No. 2 Regular Expressions Regular expressions are an extremely useful tool for manipulating.
1 CSE 390a Lecture 7 Regular expressions, egrep, and sed slides created by Marty Stepp, modified by Jessica Miller
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/23.
CS 330 Programming Languages 10 / 10 / 2006 Instructor: Michael Eckmann.
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
slides created by Marty Stepp
$address =~ m/(\d*.*)\n(.*?, ([A-Z]{2}) (\d{5})-?(\d{0,5})/ $address =~ m/(\d*.*)\n(.*?, ([A-Z]{2}) (\d{5})-?(\d{0,5})/
More on Regular Expressions Regular Expressions More character classes \s matches any whitespace character (space, tab, newline etc) \w matches.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
REGULAR EXPRESSIONS CHAPTER 14. REGULAR EXPRESSIONS A coded pattern used to search for matching patterns in text strings Commonly used for data validation.
Last Updated March 2006 Slide 1 Regular Expressions.
Regular Expression Darby Tien-Hao Chang (a.k.a. dirty) Department of Electrical Engineering, National Cheng Kung University.
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’
PHP Workshop ‹#› Data Manipulation & Regex. PHP Workshop ‹#› What..? Often in PHP we have to get data from files, or maybe through forms from a user.
INFO 320 Server Technology I Week 7 Regular expressions 1INFO 320 week 7.
PHP Using Strings 1. Replacing substrings (replace certain parts of a document template; ex with client’s name etc) mixed str_replace (mixed $needle,
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
Python Regular Expressions Easy text processing. Regular Expression  A way of identifying certain String patterns  Formally, a RE is:  a letter or.
Regular Expressions.
Quiz 30 minutes 10 questions No talking, texting, collaboration, etc…
Post-Module JavaScript BTM 395: Internet Programming.
BY Sandeep Kumar Gampa.. What is Regular Expression? Regex in.NET Regex Language Elements Examples Regular Expression API How to Test regex in.NET Conclusion.
VBScript Session 13.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Corpus Linguistics- Practical utilities (Lecture 7) Albert Gatt.
C# Strings 1 C# Regular Expressions CNS 3260 C#.NET Software Development.
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.
Satisfy Your Technical Curiosity Regular Expressions Roy Osherove Methodology & Team System Expert Sela Group The.
Regular Expressions in Perl CS/BIO 271 – Introduction to Bioinformatics.
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.
12. Regular Expressions. 2 Motto: I don't play accurately-any one can play accurately- but I play with wonderful expression. As far as the piano is concerned,
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.
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
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.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 5 – Regular Expressions, grep, Other Utilities.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
May 2006CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
Python Pattern Matching and Regular Expressions Peter Wad Sackett.
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.
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 Copyright Doug Maxwell (
RE Tutorial.
Regular Expressions Upsorn Praphamontripong CS 1110
Regular Expressions 'RegEx'.
Looking for Patterns - Finding them with Regular Expressions
Advanced Regular Expressions
CS 1111 Introduction to Programming Fall 2018
Regular Expressions
REGEX.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
What We Want To Do User enters: Mary Smith
Presentation transcript:

Regex Wildcards on steroids

Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the next level * 10 (largest number I can think of). Useful tool for anyone not just developers. – Powerful search utility in most tools (Visual Studio, Word, Excel, …)

Literals Literal characters in regex are any character that you want to literally match. – “Google” in regex will match anything with “Google” in it regardless of what is before or after it. Will match “Googleplex” – “\bGoogle\b” in regex is stating that you want to match the whole word, solves the above mentioned problem.

Wildcards “*” means match this 0-infinite times “+” means match this 1-infinite times “.” mean match any character (except end of line) With the above you can see that “.*” would match anything and everything until it hits the first line break IE Windows:“\r\n” or UNIX:“\r”

Groups Groups allow you to create character groups. “[a-z]” will match any character that is a lowercase letter. “[0-9]” will match any digit. “[a-zA-Z]” will match any character that is lowercase or uppercase “[aZd3]” will match only the characters defined in the group “a”, “Z”, “d”, and “3”. “[^0-9]” will match anything that is not a number

Pop Quiz Write a regular expression to find a phone number matching the following pattern (xxx)xxx-xxxx \([0-9][0-9][0-9]\)[0-9][0-9][0-9]-[0-9][0-9][0- 9][0-9] – Why did we have to use “\(“ and “\)”? – A “\” is to escape a regex special character – A “(“ and “)” are special characters meaning capture to backreference (capturing group)

Capturing Groups These are handy for the replace section of Find and Replace. “(“ followed by a “)” creates a capturing group that is back referenced automatically by it’s index (non-zero) in the regex, some languages allow named capture groups. “(.*)” captures any character (except line break) and puts it into back reference 1.

DEMO Word Visual Studio Notepad++

Don’t go. crazy Be wary regular expressions are greedy by default. Example: – This is like hell this merchant just keeps wanting to sell...it's so frustrating – “.*?ell” non-greedy – “.*ell” greedy

Special Characters “\d” is any number or equivalent to “[0-9]” “\D” is the opposite of the above or equivalent to “[^0-9]” “\w” is any letter, number, or underscore or equivalent to “[0-9a-zA-Z_]” “\W” is the opposite of the above or equivalent to “[^0-9a-zA-Z_]” “\s” is any whitespace character (spaces, tabs, and linebreaks) “\S” is the opposite of the above

Optimizing It is always valuable to be as specific as possible since regex is greedy. “^” matches the beginning of string “$” matches the end of string “^\(\d\d\d\)\d\d\d-\d\d\d\d$” is perfect if the whole string is suppose to be a phone number and will be faster than “\(\d\d\d\)\d\d\d-\d\d\d\d”

Character Counts Specifying the number of times you want a thing to happen “\d{3}” will match 3 digits “\d{1,3}” will match 1 to 3 digits

Pop Quiz Q: Write a regular expression to find a phone number matching the following pattern (xxx)xxx-xxxx A: “\(\d{3}\)\d{3}-\d{3}”

DEMO Show how to code with Regex