Unit 11 –Reglar Expressions Instructor: Brent Presley.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Tutorial 14 Working with Forms and Regular Expressions.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
JavaScript, Third Edition
Introduction to regular expression. Wéber André Objective of the training Scope of the course  We will present what are “regular expressions”
CST JavaScript Validating Form Data with JavaScript.
Regex Wildcards on steroids. Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the.
More on Regular Expressions Regular Expressions More character classes \s matches any whitespace character (space, tab, newline etc) \w matches.
An Introduction to TokensRegex
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
REGULAR EXPRESSIONS CHAPTER 14. REGULAR EXPRESSIONS A coded pattern used to search for matching patterns in text strings Commonly used for data validation.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Tutorial 14 Working with Forms and Regular Expressions.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
Regular Expressions in.NET Ashraya R. Mathur CS NET Security.
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
Modern JavaScript Develop And Design Instructor’s Notes Chapter 10 – Working with Forms Modern JavaScript Design And Develop Copyright © 2012 by Larry.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
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.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Copyright © 2009 Lumina Decision Systems, Inc. Regular Expressions in Analytica 4.2 Lonnie Chrisman Lumina Decision Systems Analytica User Group 9 July.
Regular Expressions. 2 3 Using Regular Expressions Regular expressions give you much more power to handle strings in a script. They allow you to form.
PHP with Regular Expressions Web Technologies Computing Science Thompson Rivers University.
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.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Regular Expressions. Overview Regular expressions allow you to do complex searches within text documents. Examples: Search 8-K filings for restatements.
Regular Expressions for PHP Adding magic to your programming. Geoffrey Dunn
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming 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,
Javascript’s RegExp. RegExp object Javascript has an Object which compiles Regular Expressions into a Finite State Machine The F.S.M. is internal, and.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
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.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
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.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
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.
10 – Java Script (3) Informatics Department Parahyangan Catholic University.
LING 408/508: Programming for Linguists Lecture 14 October 19 th.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
7 Copyright © 2009, Oracle. All rights reserved. Regular Expression Support.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
#N14 Pattern Value (aka Substring attribute) SDD 1.1 Initial Discussion XXX = [Proposal | Initial Discussion | General Direction Proposal]
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
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.
Strings Robin Burke IT 130. Outline Objects Strings methods properties Basic methods Form validation.
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.
JavaScript, Sixth Edition
Regular Expressions Upsorn Praphamontripong CS 1110
Regular Expressions 'RegEx'.
CS 330 Class 7 Comments on Exam Programming plan for today:
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 ©
Scope, Objects, Strings, Numbers
Working with Forms and Regular Expressions
Advanced Find and Replace with Regular Expressions
Functions, Regular expressions and Events
Lecture 25: Regular Expressions
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
Lecture 23: Regular Expressions
Presentation transcript:

Unit 11 –Reglar Expressions Instructor: Brent Presley

OVERVIEW Most languages today support regular expressions Including HTML5’s pattern attribute Though not standard, most languages’ implementation of regular expressions are similar

Regular expressions are defined using special control characters. The control characters are combined to form patterns that are then used to search, replace or validate other strings to see if they match the pattern.

We will focus on using regular expressions to validate user entries. –They can be used to search and replace inside of strings, but most languages have other functions to do this (though they may not have all the power regular expressions have)

EXCEPTION CHARACTER "\" is the exception character –used to designate some control group.. ie \d –used to remove special meaning from control characters. normally represents any character is allowed \. inserts a period into the pattern- requiring that character to be only a period

REGULAR EXPRESSION CONTROL CHARACTERS

SYNTAX ( ) can be used to group control characters ^ and $ are both used in many (many) JavaScript regular expression patterns to ensure the string includes no additional characters.

sample regular expressions phone /^\d{3}-\d{3}-\d{4}$/ Credit Card /^(\d{4}-){3}\d{4}$/ zip code /^\d{5}(-\d{4})?$/ start stop any digit repeat 3 times optional repeat 0 or 1 times

REGEX SITES expressions.info/examples.htmlhttp:// expressions.info/examples.html

A MORE COMPLICATED EXAMPLE /^(\(\d{3}\) ?)?\d{3}[-.]\d{4}$/ \( = escapes the special character for "(" meaning that the character at this location must be a ( 'space'? = optional space [-.] = character choice of these

DEFINING REGEX PATTERN VARIABLE What does this match? var pattern = /^.*$/;

WHAT IS THIS ONE?

DEFINING REGEX PATTERN VARIABLE JavaScript var pattern = /^.*$/; //matches anything Visual Studio using System.Text.RegularExpressions.Regex; string pattern note that backslashes must be doubled in string pattern literals or you can to the beinning of the string

USING REGULAR EXPRESSIONS if(pattern.test(str)) –will return a boolean if(str.match(pattern) –match returns an array of strings that match the pattern. (false if 0 elements)

JAVASCRIPT SYNTAX define the pattern, then check to see if the pattern matches.

EXAMPLES in unit11.js –ValidateSection –ValidatePhone –ValidateCreditCard –ValidateHexValue

ELIMINATE ^ AND $ looks for the pattern anywhere in the string index = str.search(pattern) –gives a 0 based index of first occurrence –returns 1 if not found

RETURNED ARRAY if you do not have /g in the pattern –finds all occurrences of an expression foundArray=str.match(pattern) –returns an array with 3 elements –[0]- text that matches the pattern –[1]- index of matching pattern –[2] -original string

ADDING G TO THE SEARCH foundArray = str.match(gPattern); Returns an array where each element contains a string that matched the pattern –Found matches will not overlap –Search continues after the previous match Example: if searching for 3 digits, 1234 will match 123, but not 234 (search continues after 3)

REPLACE Replace text that matches an expression newString = str.replace(pattern, newText) Replaces first occurrence of text matching the pattern with newText Include g at end of pattern to replace all (global)

IN CREDIT CARD replace any space with a dash