PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional.

Slides:



Advertisements
Similar presentations
FORM VALIDATION Faheem Ahmed Khokhar. FORM VALIDATION Faheem Ahmed Khokhar.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Chapter 14 Perl-Compatible Regular Expressions Part 1.
Regular Expression Original Notes by Song Guo. What Regular Expressions Are Exactly - Terminology a regular expression is a pattern describing a certain.
Data Manipulation & Regular Expressions CSCI 215.
ISBN Chapter 6 Data Types Character Strings Pattern Matching.
COS 381 Day 22. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
Tutorial 14 Working with Forms and Regular Expressions.
Validating user input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Read Lecturer.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
REGULAR EXPRESSIONS CHAPTER 14. REGULAR EXPRESSIONS A coded pattern used to search for matching patterns in text strings Commonly used for data validation.
Stupid Browser Tricks with PHP and JavaScript By Chris Winikka.
Strings IDIA 618 Spring 2013 Bridget M. Blodgett.
Tutorial 14 Working with Forms and Regular Expressions.
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.
Strings Representation and Manipulation. Objects Objects : Code entities uniting data and behavior – Built from primitive data types.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
Sys.Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 18: Regular Expressions in PHP.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
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.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction: Regular Expressions, Regular Languages Autumn 2011 CSE 3111.
Strings in PHP Working with Text in PHP Strings and String Functions Mario Peshev Technical Trainer Software University
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Yet more on XSLT. Regular expression handling in EXSLT We saw that the EXSLT extensions are divided into a group of modules, each of which has its own.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Programming in Perl regular expressions and m,s operators Peter Verhás January 2002.
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.
Post-Module JavaScript BTM 395: Internet Programming.
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.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
C# Strings 1 C# Regular Expressions CNS 3260 C#.NET Software Development.
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
1 PHP Intro PHP Strings After this lecture, you should be able to: Manipulate and Output PHP Strings: Manipulate and Output PHP Strings: Single- or Double-quoted.
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,
CS346 Regular Expressions1 Pattern Matching Regular Expression.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
10 – Java Script (3) Informatics Department Parahyangan Catholic University.
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.
INT222 – Internet Fundamentals Week 11: RegExp Object and HTML5 Form Validation 1.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
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.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Assignment #2. Regular Expression (RE) Represent a string pattern – Consists of regular characters and wild cards Assignment #2: implement a subset of.
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.
Arrays and Strings. Arrays in PHP Arrays are made up of multiple memory blocks, each with the same name and differentiated by an index number Each block.
Computer Programming ||
Lecture 19 Strings and Regular Expressions
Perl-Compatible Regular Expressions Part 1
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 ©
CSE 311 Foundations of Computing I
Chapter 7: Strings and Characters
Embedded PHP in HTML 5 & Strings in PHP
Representation and Manipulation
Data Manipulation & Regex
Regular Expression: Pattern Matching
PHP –Regular Expressions
Presentation transcript:

PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional

PHP’s Regular Expression Functions (Perl Compatible) preg_grep() preg_match() preg_match_all() preg_quote() preg_replace()

preg_grep() array preg_grep(string pattern, array input [, flags]) searches all elements of an array, returning an array consisting of all elements matching a certain pattern. <?php $foods = array("pasta", "steak", "fish", "potatoes"); $food = preg_grep("/^p/", $foods); print_r($food); ?>

preg_match() int preg_match(string pattern, string string [, array matches] [, int flags [, int offset]]]) searches a string for a specific pattern, returning TRUE if it exists, and FALSE otherwise. <?php $line = "vim is the greatest word processor ever created!"; if (preg_match("/\bVim\b/i", $line, $match)) print "Match found!"; ?>

preg_match_all() int preg_match_all(string pattern, string string, array pattern_array [, int order]) matches all occurrences of a pattern in a string, assigning each occurrence to an array in the order you specify via an optional input parameter. <?php $userinfo = "Name: Zeev Suraski Title: PHP Guru "; preg_match_all("/ (.*) /U", $userinfo, $pat_array); printf("%s %s", $pat_array[0][0], $pat_array[0][1]); ?>

preg_quote() string preg_quote(string str [, string delimiter]) inserts a backslash delimiter before every character of special significance to regular expression syntax. These special characters include $ ^ * ( ) + = { } [ ] | \\ : <?php $text = "Tickets for the bout are going for $500."; echo preg_quote($text); ?>

preg_replace() mixed preg_replace(mixed pattern, mixed replacement, mixed str [, int limit]) replaces all occurrences of pattern with replacement, and returning the modified result <?php $text = "This is a link to echo preg_replace("/ " \${0} ", $text); ?>