Chapter 14 Perl-Compatible Regular Expressions Part 1.

Slides:



Advertisements
Similar presentations
1. Write an Excel text function in cell Company Data!A4, which may be copied down, to string together the first and last name with only the first letter.
Advertisements

Regular Expression ASCII Converting. Regular Expression Regular Expression is a tool to check if a string matches some rules. It is a very complicated.
Data Manipulation & Regular Expressions CSCI 215.
Validating user input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
IS 1181 IS 118 Introduction to Development Tools Chapter 4 String Manipulation and Regular Expressions.
Regular expression. Validation need a hard and very complex programming. Sometimes it looks easy but actually it is not. So there is a lot of time and.
Scripting Languages Chapter 8 More About Regular Expressions.
Form Validation CS What is form validation?  validation: ensuring that form's values are correct  some types of validation:  preventing blank.
UNIX Filters.
Regex Wildcards on steroids. Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the.
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.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
CSCE 121: Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 20: Regular Expressions 1.
1 Perl Regular Expressions in SAS 9 Ruth Yuee Zhang, CFE Jan 10, 2005.
Using Regular Expressions in Java for Data Validation Evelyn Brannock Jan 30, 2009.
Sys.Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 18: Regular Expressions in PHP.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
A little PHP. Enter the simple HTML code seen below.
PHP Using Strings 1. Replacing substrings (replace certain parts of a document template; ex with client’s name etc) mixed str_replace (mixed $needle,
Finding the needle(s) in the textual haystack
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
1 DIG 3134 – Lecture 10: Regular Expressions and preg_match in PHP and Validating Inputs Michael Moshell University of Central Florida Internet Software.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
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.
Regular Expressions.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
PHP with Regular Expressions Web Technologies Computing Science Thompson Rivers University.
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.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
PHP| SCK3633 Web Programming | Jumail, FSKSM, UTM, 2006 | Last Updated March 2006 Slide 1 Regular Expressions.
Regular Expressions Nils Murrugarra
 2003 Jeremy D. Frens. All Rights Reserved. Calvin CollegeDept of Computer Science(1/8) Regular Expressions in Java Joel Adams and Jeremy Frens Calvin.
Overview A regular expression defines a search pattern for strings. Regular expressions can be used to search, edit and manipulate text. The pattern defined.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming regular expressions.
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.
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.
PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional.
Flex Fast LEX analyzer CMPS 450. Lexical analysis terms + A token is a group of characters having collective meaning. + A lexeme is an actual character.
CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
1 DIG 3563: Lecture 2a: Regular Expressions Michael Moshell University of Central Florida Information Management.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
1 Validating user input is the bane of every software developer’s existence. When you are developing cross-browser web applications (IE4+ and NS4+) this.
Java Script Pattern Matching Using Regular Expressions.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions.
Operators Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
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 Day 11 LING Computational Linguistics Harry Howard Tulane University.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
Variable Variables A variable variable has as its value the name of another variable without $ prefix E.g., if we have $addr, might have a statement $tmp.
Pattern Matching: Simple Patterns. Introduction Programmers often need to scan a file, directory, etc. for a specific substring. –Find all files that.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
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.
Regular Expressions.
Perl-Compatible Regular Expressions Part 1
Validation using Regular Expressions
Presentation transcript:

Chapter 14 Perl-Compatible Regular Expressions Part 1

preg_match The match function is int preg_match(string $pattern, string $str ) – 1 st argument is the pattern – 2 nd argument is the subject string – Returns number of matches found: 1 (true) if there is a match – it stops at the first match found! 0 (false) otherwise

pcre.php Script 14.1 on page php php ch14\pcre.php

Character Classes [A-Z]uppercase letter [a-z]lowercase letter [0-9]digit {5}exactly five {3,}three or more {1,4}one to four 4

Metacharacters ^beginning of string $end of string |or 5

Regular Expression Username – 5 to 10 lowercase letters? $pattern = '/^[a-z]{5,10}$/'; if (!preg_match($pattern, $username)) { echo " $username is invalid. "; } 6

Regular Expressions Social Security Number $pattern = '/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/'; if (!preg_match($pattern, $ssn)) { echo " $ssn is invalid. "; } 7

Character classes \dany digit [0-9] \Dany non-digit [^0-9] \wAny letter, number, or underscore [A-Za-z0-9_] \WAnything that is not a letter, number, or underscore [^A-Za-z0-9_] 8

Character classes \swhitespace (space, tab, new line, etc.) [\f\r\t\n\v] \SAny non-whitespace [^\f\r\t\n\v] 9

Regular Expressions Social Security Number $pattern = '/^\d{3}-\d{2}-\d{4}$/'; if (!preg_match($pattern, $ssn)) { echo " $ssn is invalid. "; } 10

Metacharacters [0-9]** = zero or more [A-Z]++ = one or more.. = match any character ([A-Z]\. )?? = either zero or one 11

Regular Expressions Last name: Frank $pattern = '/^[A-Z][a-z]+$/'; if (!preg_match($pattern, $last)) { echo " $last is invalid. "; } 12

Regular Expressions Name: Charles Frank or Charles E. Frank $pattern = '/^[A-Z][a-z]+ ([A-Z]\. )?[A-Z][a-z]+ $/'; if (!preg_match($pattern, $name)) { echo " $name is invalid. "; } 13

Zip Code Page 444 /^(\d{5}(-\d{4})?$/

Address Page 445