LING 408/508: Computational Techniques for Linguists Lecture 18
Adminstrivia Reminder: no class next Tuesday (out of town @ meeting)
Today's Topics Homework 6 graded Part 2: Homework 6 review Last time: http://elmo.sbs.arizona.edu/sandiway/ling508-18/bmi-gauge.html
Homework 6 Review Javascript functions: Term project idea: shuffle() solved() Term project idea: animate solution 16!/2 = 10,461,394,944,000 valid configurations i.e. write a function solve() https://cornellmath.wordpre ss.com/2008/01/27/puzzles- groups-and-groupoids/ Stage 1: put 1 and 2 into position, get 3 and 4 into the corner Stage 2: repeat for 5-8 Stage 3: put 9 and 13 into position Stage 4: solve rest of the pieces
Javascript regular expressions Let's write our own browser-based tester to help you learn regular expressions: form See: http://elmo.sbs.arizona.edu/~sandiway/ling508-18/re-test.html
Javascript regular expressions <input name=str> <input name=g> <input name=re>
Javascript regular expressions optional What Javascript provides: RegEx object var re = new RegEx(string, flags) var re = /[A-Z]([a-z])*/gi (g= global; i=ignore case) Methods: var a = string.match(re) returns an array [entire match, ...submatches…] var a = regex.exec(string) returns an array different behaviors (under global flag)
Javascript Regexp Tester Let's try the code: http://elmo.sbs.arizona.edu/~sandiway/ling508-18/re-test.html Mr. ([A-Z][a-z]*) Mr\. ([A-Z][a-z]*)
Javascript Regexp Tester Useful property regex.lastIndex
Regular expression syntax http://www.w3schools.com/jsref/jsref_obj_regexp.asp
Regular expression syntax
Regular expression syntax
Regular expression syntax
Regular expression syntax
Regex Replace We'll also need the method replace(): var regex = new RegExp(re_s,flag_s); modified_string = string.replace(regex,replacement) replacement string can contain $n (NOT \n) (n = group number) developer.mozilla.org
Regex Replace Let's try it out: http://elmo.sbs.arizona.edu/~sandiway/ling508-18/rep-test.html