UMass Lowell Dept. of Computer Science

91.461 GUI Programming I

Fall 2015 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 24

Introduction to Regular Expressions (continued)

Tuesday, November 24, 2015

A video of this class is (or will be) posted at:   http://echo360.uml.edu/heines201516/guiprogramming1.html


Handouts and Materials


Openings / Announcements / Reminders

Yet another wonderful post I was referred to by a friend as a follow-up to the terrorism in France

http://www.bbc.com/news/world-europe-34862437

Wonderful site for test regular expressions

https://regex101.com/

Interesting Firefox vs. Chrome differences in support for CSS clipping and masking

https://css-tricks.com/clipping-masking-css/

The name of the web development platform that I couldn’t think of last week is Drupal

https://www.drupal.com/

Currently planning a final short quiz on Tuesday, December 1st


Class Notes

Working with Associative Arrays in JavaScript

See the challenge posted in my response to Ramon Meza’s posting on Piazza


Pattern Matching  (continued)

Review from last class ...

Regular expressions are made up of several parts

Normal characters

Character classes

Pattern Metacharacters

Metacharacter Interpretation Example
. Matches any single character except newline ".ba" matches barbara and yabba
[cccccc] Matches any single character listed in this set "[Vv]ariable[12]" matches variable1 and Variable2
[^cccccc] Matches any single character not listed in this set "value[^01]" matches valuex and value2 but not value1 or value0
[c-c] Matches any single character within the range in this set "age[5-8]" matches age5, age6, age7 and age8
$ Matches the end of a string (or line if the "m modifier is used) "txt$" matches test.txt but not test.txtfile
^ Matches the beginning of a string (or line if the "m modifier is used) "^ja" matches javascript and java but not Wow, Java’s cool!
* Matches 0 or more of the preceding regular expression "value[0-9]*" matches value1, value10 and value
+ Matches 1 or more of the preceding regular expression "value[0-9]+" matches value1 and value999, but not value
? Matches 0 or 1 of the preceding regular expression (i.e., optional) "html?" matches html and htm
{quantity} Matches exactly quantity of the preceding regular expression "value[0-9]{3}" matches value001, value010 and value123, but not value1
{min,max} Matches at least min but no more than max of the preceding regular expression "value[0-9]{3,5}" matches value001, log0011 and log12345, but not log35
| Matches either the expression on the left or the right of the | "Mr\.|Mrs\.|Ms\." matches Mr. or Mrs. or Ms.
Escape
Sequence
Interpretation
\' Single quotation mark
\" Double quotation mark
$ The $ sign
\a Alarm (a small bell sound)
\b Backspace
\e Escape
\E End \L, \Q, or \U
\f Form feed
\l Lowercase next character
\L Lowercase all following characters until \E
\n New line
\Q Backslash all following non-alphanumeric characters until \E
\r Carriage return
\t Tab
\u Uppercase next character
\U Uppercase all following characters until \E
\\ Single backslash
Escape
Sequence
Interpretation
\A Match the beginning of a string (same as ^ if /m is not used)
\B Match a non-word boundary
\b Match a word boundary (between \w and \W)
\cx Match control character x (for example, \cC matches Ctrl/C)
\d Match a digit character [0-9]
\D Match a non-digit character [^0-9]
\nnn An octal ASCII value
\s Match a white space character [ \t\n\r\f]
\S Match a non-white space character [^ \t\n\r\f]
\w Match a “word” (alphanumeric) character [a-zA-Z_0-9]
\W Match a non-word character [^a-zA-Z_0-9]
\xnn A hexadecimal ASCII value
\Z Match the end of a string or before a new line (same as $ if /m is not used)
\z Match the end of a string

New material begins here ...

Using Regular Expressions with JavaScript

Syntax

var re = /ab+c/ ;

Note that there are no quotes!

RegExs can be used with


Example use with the jQuery Validator

Run this code


Example for adding commas to large numbers

JavaScript Function

Test Program

Run this code


ES2015 Code School Video

“The Shape of JavaScript to Come”

Using let  (6:47)

Using let in for Loops  (3:54)

Using const  (4:09)



This is document http://jesseheines.com:8080/~heines/91.461/91.461-2015-16f/461-lecs/lecture24.jsp.  It was last modified on Friday, August 26, 2022 at 4:09 PM.
Copyright © 2022 by Jesse M. Heines.  All rights reserved.  May be freely copied or excerpted for educational purposes with credit to the author.