Regular Expressions 101 Danny Bryant City of Atlanta.

Slides:



Advertisements
Similar presentations
Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Advertisements

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.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
CS 497C – Introduction to UNIX Lecture 31: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Using regular expressions Search for a single occurrence of a specific string. Search for all occurrences of a string. Approximate string matching.
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
 Danny Bryant City of Atlanta. Information Technology Manager, Sr. – City of Atlanta User Groups:ODTUG, OAUG, IOUG Publications:ODTUG – Why I Joined.
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
1 Overview Regular expressions Notation Patterns Java support.
Scripting Languages Chapter 8 More About Regular Expressions.
CSE467/567 Computational Linguistics Carl Alphonce Computer Science & Engineering University at Buffalo.
Form Validation CS What is form validation?  validation: ensuring that form's values are correct  some types of validation:  preventing blank.
Lecture 6 29/1/15. Number functions Number functions take numbers as input, change them, and output the results as numbers. 2.
Shell Script Examples.
Regular Language & Expressions. Regular Language A regular language is one that a finite state machine (fsm) will accept. ‘Alphabet’: {a, b} ‘Rules’:
Last Updated March 2006 Slide 1 Regular Expressions.
MORE APPLICATIONS OF REGULAR EXPRESSION By Venkata Sai Pundamalli id:
Language Recognizer Connecting Type 3 languages and Finite State Automata Copyright © – Curt Hill.
Overview of the grep Command Alex Dukhovny CS 265 Spring 2011.
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
REGULAR EXPRESSIONS. Lexical Analysis Lexical analysers can be constructed by programs such as LEX These programs employ as input a description of the.
8 Copyright © 2006, Oracle. All rights reserved. Regular Expression Support.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
1 CSC 594 Topics in AI – Text Mining and Analytics Fall 2015/16 4. Document Search and Regular Expressions.
Regular Expression in Java 101 COMP204 Source: Sun tutorial, …
Programming in Perl regular expressions and m,s operators Peter Verhás January 2002.
CSC 352– Unix Programming, Spring 2015 April 28 A few final commands.
Regular Expression Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
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.
Database Programming Sections 13–Creating, revoking objects privileges.
Regular Expressions – An Overview Regular expressions are a way to describe a set of strings based on common characteristics shared by each string in.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
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.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
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.
©Brooks/Cole, 2001 Chapter 9 Regular Expressions ( 정규수식 )
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,
©Brooks/Cole, 2001 Chapter 9 Regular Expressions.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
1 DIG 3563: Lecture 2a: Regular Expressions Michael Moshell University of Central Florida Information Management.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
7 Copyright © 2009, Oracle. All rights reserved. Regular Expression Support.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
Pattern Matching: Simple Patterns. Introduction Programmers often need to scan a file, directory, etc. for a specific substring. –Find all files that.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
Understanding Regular Expressions – Peter Robson – Finnish OUG Helsinki, April JustSQL.com Understanding Regular Expressions Peter Robson Technical.
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
Introducing Oracle Regular Expressions
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Regular Expressions in Perl
Regular Expressions and Grep
REGEX.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
How to cheat at Scrabble An intro to regular expressions
Presentation transcript:

Regular Expressions 101 Danny Bryant City of Atlanta

Danny Bryant IT Manager, Sr.- City of Atlanta About the Danny Bryant User Groups:ODTUG | OAUG | IOUG Publications & Media ODTUG (blog) – How’d You First Get Involved with ODTUG? RMOUG – SQL>SELECT Regular Expressions: A Love/Hate Relationship Oracle Podcast SQL Dev 4.0 in Action at the City of Atlanta

Agenda Simple Pattern Matching What are Regular Expressions META Characters ▫Examples Regular Expression Function ▫Examples

Simple Pattern Matching LIKE Operator %(multiple characters) _ (single character)

Simple Pattern Matching ‘%” LIKE Operator with ‘%” SELECT first_name, last_name FROM employees LIKE% WHERE last_name LIKE ‘Ba%'

Simple Pattern Matching ‘_’ LIKE Operator with ‘_’ SELECT first_name, last_name FROM employees LIKE WHERE last_name LIKE ‘Ba_da’

Simple Pattern Matching What if you needed to find all words where every second character is a vowel? Regular Expressions

What are Regular Expressions? Methods of describing both simple and complex patterns for searching and manipulating Uses META Characters for pattern matching Oracle’s implementation is an extension of the POSIX (Portable Operating System for UNIX)

META Characters SymbolDescription ^Marks the start of a line $Marks the end of a line [ ]Matching list |Operator for specifying alternative matches (logical OR) ?Matches zero or one occurrence.Matches any character except NULL {m} m Matches exactly m times {m,n} mn Matches at least m times but no more than n times [: :]Specifies a character class and matches any character in the class \Escape character

SymbolDescription +Matches one or more occurrences *Matches zero or more occurrences ()Grouping for expression \nBack-reference expression META Characters

Examples

^ Beginning of a line Example: ^(Oracle) Match Oracle Open World √ The Oracle at Delphi X Oracle √

$ End of a line Example: (Oracle)$ Match Welcome to Oracle √ The Oracle at Delphi X Oracle √

(string1|string2)logical OR Example: Ste(v|ph)en Match Stephen √ Stefan X Steven √

.(dot) Single character match Example: re.d Match read √ rear X reed √

. Breakdown (re.d) CharacterCheckSuccess r r e a d r e a r r e e d √√√√√√ e r e a d r e a r r e e d √√√√√√. (A-Z,a-z) r e a d r e a r r e e d √√√√√√ d r e a d r e a r r e e d √X√√X√

m {m} Matches exactly m times Example: s{2} Match password √ sister X essential √

{m} Breakdown (s{2}) passwordChecksisterCheck pX s √ aX i X s√ s √ s√ t X wX e X oX r X rX dX

*(star) Matches zero or more Example: ab*c Match abc √ acc X ac √

* Breakdown (ab*c) abcCheckaccCheck a√a√ b√cX c√cX

Regular Expression Functions Set of SQL functions used to search and manipulate strings using Regular Expressions These functions can be used on any data type that holds character data (CHAR, VARCHAR, CLOB, etc) The Regular Expression must be enclosed in single quote marks

Function nameDescription REGEXP_LIKESimilar to the LIKE operator but allows for the use of regular expressions in matching REGEXP_REPLACESearch and replace text using regular expression pattern REGEXP_INSTRSearches for a string using regular expression pattern and returns the position when match is found REGEXP_SUBSTRSearches for a string using regular expression pattern and returns the matched substring REGEXP_COUNTReturns the number of times a pattern appears in the string. Regular Expression Functions

REGEXP_LIKE Similar to the LIKE operator but allows for the use of regular expressions in matching

REGEXP_LIKE All employees first name of Steven or Stephen

REGEXP_LIKE All employees first name of Steven or Stephen Meta CharacterDescription ^Start of the string SteBeginning letters of the string (Starts the group vIs next character a ‘v’ |OR phAre next characters ‘ph’ )End the group enEnding letters of string $End of the string

REGEXP_REPLACE Search and replace text using regular expression pattern

REGEXP_REPLACE Reformat phone number from ###.###.#### to 1 (###)-###-####

REGEXP_REPLACE Meta CharacterDescription [[:digit:]]{3}Three digits (group 1) \.Then a ‘.’ (Since the ‘.’ is a META Character, we have to use the \ to ‘escape’ it) [[:digit:]]{3}Three digits (group 2) \.Then a ‘.’ [[:digit:]]{4}Four digits (group 3)

REGEXP_REPLACE ReplacementsDescription (sample ) 1Start with a 1 (\1)Enclose group 1 in () -> (404) -Add a ‘-’ \2Group 2 -> 777 -Add a ‘-’ \3Group 3 -> 9311 RESULT1 (404)

REGEXP_INSTR Searches for a string using regular expression pattern and returns the position when match is found

REGEXP_INSTR Search for addresses that don’t start with a number and list the position of the first non-alpha character

REGEXP_INSTR Search for addresses that don’t start with a number and list the position of the first non-alpha character Meta CharacterDescription [Start of the expression ^NOT [:alpha:]Alpha characters ]End of the expression

REGEXP_SUBSTR Searches for a string using regular expression pattern and returns the matched substring

REGEXP_SUBSTR Only return POSITION department name

REGEXP_SUBSTR Only return POSITION department name Meta CharacterDescription \.Escape the ‘.’ [A-z-]+Matches one or more occurrences of alpha characters \.Escape the ‘.’ 1Starting position 1Nth occurrences ‘i’Ignore case 2Sub-expression to return

REGEXP_COUNT Returns the number of times a pattern appears in the string. Scenario 1: DNA sequence of a mouse. Need to find the number of times the sequence of Cytosine, Adenine, Thymine (cat) proteins occur. Scenario 2: All rows where there is an ‘i’ in the first name

REGEXP_COUNT Scenario 1

REGEXP_COUNT Scenario 2

Q/A