Regular Expressions A regular expression is a pattern that defines a string or portion thereof. When comparing this pattern against a string, it'll either.

Slides:



Advertisements
Similar presentations
Session 3BBK P1 ModuleApril 2010 : [#] Regular Expressions.
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
BBK P1 Module2010/11 : [‹#›] Regular Expressions.
Searching using regular expressions. A regular expression is also a ‘special text string’ for describing a search pattern. Regular expressions define.
Regular Expression Original Notes by Song Guo. What Regular Expressions Are Exactly - Terminology a regular expression is a pattern describing a certain.
Linux+ Guide to Linux Certification, Second Edition
Regular Expressions. u A regular expression is a pattern which matches some regular (predictable) text. u Regular expressions are used in many Unix utilities.
Using regular expressions Search for a single occurrence of a specific string. Search for all occurrences of a string. Approximate string matching.
Regular Expressions In ColdFusion and Studio. Definitions String - Any collection of 0 or more characters. Example: “This is a String” SubString - A segment.
JavaScript, Third Edition
Introduction to C Programming
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
Regular Expressions. String Matching The problem of finding a string that “looks kind of like …” is common  e.g. finding useful delimiters in a file,
More on Regular Expressions Regular Expressions More character classes \s matches any whitespace character (space, tab, newline etc) \w matches.
An Introduction to TokensRegex
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.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Regular Expressions A regular expression defines a pattern of characters to be found in a string Regular expressions are made up of – Literal characters.
Spreadsheets Objective 6.02
2 Explain advanced spreadsheet concepts and functions Advanced Calculations 1 Sabbir Saleh_Lecture_17_Computer Application_BBA.
Last Updated March 2006 Slide 1 Regular Expressions.
Regular Expressions Week 07 TCNJ Web 2 Jean Chu. Regular Expressions Regular Expressions are a powerful way to validate and format text strings that may.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
Language Recognizer Connecting Type 3 languages and Finite State Automata Copyright © – Curt Hill.
Regular Expression Darby Tien-Hao Chang (a.k.a. dirty) Department of Electrical Engineering, National Cheng Kung University.
 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.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Perl 6 Update - PGE and Pugs Dr. Patrick R. Michaud April 26, 2005.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Linux+ Guide to Linux Certification, Third Edition
Python Regular Expressions Easy text processing. Regular Expression  A way of identifying certain String patterns  Formally, a RE is:  a letter or.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Built-in Data Structures in Python An Introduction.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
VBScript Session 13.
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 for PHP Adding magic to your programming. Geoffrey Dunn
Appendix A: Regular Expressions It’s All Greek to Me.
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.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
1 DIG 3563: Lecture 2a: Regular Expressions Michael Moshell University of Central Florida Information Management.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
What are Regular Expressions?What are Regular Expressions?  Pattern to match text  Consists of two parts, atoms and operators  Atoms specifies what.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
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.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
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.
Hands-on Regular Expressions Simple rules for powerful changes.
RE Tutorial.
Regular Expressions Upsorn Praphamontripong CS 1110
Regular Expressions 'RegEx'.
Looking for Patterns - Finding them with Regular Expressions
Advanced Regular Expressions
Regular Expressions in Perl
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Pattern Matching in Strings
Advanced Find and Replace with Regular Expressions
CMSC 202 Java Primer 2.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
Presentation transcript:

Regular Expressions A regular expression is a pattern that defines a string or portion thereof. When comparing this pattern against a string, it'll either be true or false. If true, it'll return something. The return value will depend on the specific function used and its attributes.

Regular Expressions:Basics Basics of the function –REFind(reg_expression, string [, start] [, return_sub]) compares a Regular Expression to a string and if it matches all or part of the string, returns the numeric position in the string where the match starts. The optional start position allows the search to start anywhere in the string. An additional option is to return sub expressions. We'll deal with that a little later.

Regular Expressions:Basics Any Ascii character which is not a special character matches itself. –A matches A –b matches b A does not match a unless the NoCase version of the function is used –REFindNoCase() This is slightly slower, but only someone totally anal about run times will be able to tell you how much slower. :)

Regular Expressions:Basics REFindNoCase('is', 'This is a test') = 3 REFindNoCase(‘This', 'This is a test') = 1 REFind (‘t', 'This is a test') = 11

Regular Expressions:Special Characters A period (.) matches any single character A pipe (|) means either what comes before it or what comes after it. A caret (^) at the beginning of a RegEx means that the regex will only match if it starts at the beginning of the comparison string A dollar sign ($) at the end of a RegEx means that the regex will only match if it ends at the end of the comparison string

Regular Expressions:Special Characters A backslash (\) means escape the next character if it is a special one If the character after the backslash is not a special one, then it may be an escape sequence Displaying a backslash (\) is done by escaping it

Regular Expressions:Special Characters REFindNoCase(‘i.', 'This is a test') = 3 REFindNoCase(‘^is', 'This is a test') = 0 REFindNoCase(‘^t', 'This is a test') = 1 REFindNoCase(‘t$', 'This is a test') = 14 REFindNoCase(‘th|te', 'This is a test') = 1 REFind (‘th|te', 'This is a test') = 11

Regular Expressions:Escape Sequences When certain non-special characters have a backslash (\) before them, they become special. REFindNoCase(‘\d’, ‘this is 4’) = 9 \d means any number REFindNoCase(‘is \d’, ‘this is 4’) = 6

Regular Expressions:Sets A character set is a group of characters from which only one is desired [ ] – matches any single number Sets can use ranges of characters (think ascii table) [0-9] – matches any single character A dash can be represented in a set by placing it first (I.e. not in a range) [-aeiou] – matches a dash or a vowel A Carat (^) at the beginning of a set negates if (I.e. anything BUT characters in the set

Regular Expressions:Sets REFindNoCase(‘[AEIOU]’, ‘This is a test’) = 3 REFindNoCase(‘[0-9]’, ‘this is a test’) = 0 REFindNoCase(‘[0-9]’, ‘this is a 4th test’) = 11 REFindNoCase(‘[-0-9]’, ‘this-is a test’) = 5 REFindNoCase(‘[^0-9]’, ‘this is a test’) = 1 REFindNoCase(‘[^-]’, ‘this is a test’) = 1 REFindNoCase(‘[-^]’, ‘this-is a ^’) = 5

Regular Expressions:Sets ColdFusion also includes a number of predefined sets: A predefined set is called using a special name surrounded by colons –:alpha: Used within a set, it would look like REFindNoCase(‘[:alpha:]’, ‘123abc’) = 4 Can be combined with other characters in a set REFindNoCase(‘[123[:alpha:]]’, ‘123abc’) = 1

Regular Expressions:Groups A group allows a portion of a regular expression to be separated from another portion Also known as subexpressions Uses parenthesis to group things together REFindNoCase(‘(this|that):’, ‘find this:’) = 6 More uses later

Regular Expressions:Modifiers A modifier will take the previous character, set or group and say how many times it can or should exits. REFindNoCase(‘ha+’, ‘hahaha’) = 1 REFindNoCase(‘ha*’, ‘hhaha’) = 1 REFindNoCase(‘ha?’, ‘hahaha’) = 1 REFindNoCase(‘ha{2}’, ‘hahaaha’) = 3 REFindNoCase(‘ha{2,3}’, ‘hahaha’) = 3 REFindNoCase(‘ha+{3,}’, ‘hahaha’) = 0 REFindNoCase(‘(ha)+’, ‘hahaha’) = 1

Regular Expressions:Modifiers Normal modifiers are greedy, I.e. they want to match as much as they can. Using a question mark (?) after a modifier makes it lazy, I.e. it will match as little as possible REFindNoCase('a+', 'baaaa',1,1) will return aaaa REFindNoCase('a+?', 'baaaa',1,1) will return a

Regular Expressions:Line Modifiers A line modifier changes how a Regular Expression is processed REFind (‘(?i)This’, ‘this’) = 1 (?i) means perform a case insensitive search REFindNoCase('(?x)is a', 'this is a isa') = 11 (?x) means perform a search ignoring spaces REFindNoCase('(?m)^line3', ‘line1 Line2 line3)') = 13 (?m) means pay attention to the lines

Regular Expressions:Returning Structures Rather than returning a number, a Regular Expression function can be set to return a structure The structure will contain 2 keys names pos and len Each will contain a matching array holding the start position of a match and its length The first item always contains the entire match and all others contains matches from sub expressions Use the mid() function to get easy access to the return data

Regular Expressions:Returning Structures The start location must be specified and the 4 th attribute must be set to yes (1, true) String= ‘this is a finder’ Test=REFindNoCase(‘f[aeiou]n.’,string, 1, 1) Mid(string, test.pos[1], test.len[1])=“Find” Test=REFindNoCase(‘f([aeiou])n.’,string, 1, 1) Mid(string, test.pos[1], test.len[1])=“Find” Mid(string, test.pos[2], test.len[2])=“i”

Regular Expressions:Replacing REReplace(string, regex, replace, scope) Replaces the regex match in the string with the replace value Scope is one(default) or all Show lots of examples here on in

Regular Expressions:Replacing New in MX is the ability to modify the replace values using special escape codes REReplaceNoCase(‘make upper’, ‘u.+’, ‘\u\1’) Upper REReplaceNoCase(‘make upper’, ‘u.+’, ‘\U\1’) UPPER