6. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/m/
http://tinyurl.com/rx101-2
7. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/me/
http://tinyurl.com/rx101-4
8. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/./
http://tinyurl.com/rx101-5
9. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/./
http://tinyurl.com/rx101-8
10. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/.e/
http://tinyurl.com/rx101-10
11. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[aeiou]/
http://tinyurl.com/rx101-11
12. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[a-f]/
http://tinyurl.com/rx101-12
14. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[a-fw-z]/
http://tinyurl.com/rx101-13
15. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[^A-Z]/
http://tinyurl.com/rx101-14
16. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/d/
http://tinyurl.com/rx101-15
18. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/w/
http://tinyurl.com/rx101-17
20. Activity!
Write a regular expression to match
the telephone number in this text:
For a good time call Stanley: 555-1212 - you will not be disappoint.
http://tinyurl.com/rx101-a1
22. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/men?/
http://tinyurl.com/rx101-19
23. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/".*"/
http://tinyurl.com/rx101-20
24. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/".*?"/
http://tinyurl.com/rx101-21
25. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
“TMTOWTDI”
http://tinyurl.com/rx101-22
/"[^"]*"/
26. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/tw+[aeiou]/
http://tinyurl.com/rx101-23
27. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/tw*[aeiou]/
http://tinyurl.com/rx101-24
28. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[aeiou]{2}/
http://tinyurl.com/rx101-25
35. Activity!
Rewrite the telephone number regular expression
to use quantifiers.
For a good time call Stanley: 555-1212 - you will not be disappoint.
http://tinyurl.com/rx101-a1
Extra credit - extract the email address.
For a good time email stanley@aol.com you will not be disappoint.
http://tinyurl.com/rx101-a2
37. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/^[^s]+/
http://tinyurl.com/rx101-29
38. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/[^s]+$/
http://tinyurl.com/rx101-30
39. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/baw*/
http://tinyurl.com/rx101-31
40. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/bw{3}b/
http://tinyurl.com/rx101-32
41. Activity!
Go back and fix this example to find whole
words that start with ‘t’ and end in a vowel.
http://tinyurl.com/rx101-24
43. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
1. Now is the time for all good men to come to the aid of their country.
2. Chase
/"(.*?)"/
http://tinyurl.com/rx101-33
44. Replacement
str = '"Now is the time for all good men to come to the aid of their country." was proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in 1918.'puts str.gsub(/"(.*?)"/, '<i>1</i>')
str = '"Now is the time for all good men to come to the aid of their country." was proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in 1918.'puts str.gsub(/"(.*?)"/, '<i>1</i>')
<i>Now is the time for all good men to come to the aid of their country.</i> was
proposed as a typing drill by a teacher named Charles E. Weller aka
<i>Chase</i> in 1918.
45. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
1. is
2. the
3. the
4. of
/b(the|is|of)b/
http://tinyurl.com/rx101-34
46. "Now is the time for all good men to come to the aid of their country." was
proposed as a typing drill by a teacher named Charles E. Weller aka "Chase" in
1918.
/b(?:the|is|of)b/
http://tinyurl.com/rx101-35
Feedback:
- Move flags slide to before walkthrough
- How about an ending slide?
Kleene, Stephen C. (1956). "Representation of Events in Nerve Nets and Finite Automata"
Character literals
Multiple character literals
The wildcard
What if you actually want a period? Escape it! The same goes for any special character.
You can combine wildcards with literals
If you put something in brackets, it means ‘anything in the brackets’
..and you can do ranges by adding a hyphen
Note that when using big ranges like A-z, that you are using ASCII ordering, so you’ll probably be including some things you don’t expect.
..or multiple ranges
Brackets with a caret negates the match.. so here, select anything except for capital letters.
Common character classes have shortcuts, like ‘d’ for digits.
‘s’ for spaces (including tabs, spaces and newlines)
‘w’ for WORD characters (including a-z, 0-9 and _)! You can remember them by thinking of your favorite shoe marketplace, DSW!
You can invert any of those by using an upper case version.. so here we are selecting non-word characters
Quantifiers are a special syntax that dictates how many of a thing to match
Question mark means zero or one of the preceding character. Here, read this is ‘me’ followed by an optional ‘n’
Asterisk aka glob, aka the ‘Kleene Star’ means zero or more of the preceding character. It is ridiculously powerful and hungry, like Sinistar. Here we are matching everything between quotes. But you can see a problem, that we’re also blowing past two other quotes on the way to the last one. This is called a greedy glob.
We can limit the greed of the match by adding a question mark.. this will now stop matching as soon as the condition is met.
BUT, we can also write it this way. TMTOWTDI
+ means one or more of the preceding character. Here we are matching t followed by one or more word characters, followed by a vowel. Note that we do not match ‘to’
And here you can see the difference between + and *
To specify an exact number, you can put the number in curly braces! Here we are selecting all double vowels.
You can specify a minimum and maximum.. here we are looking for 3 or 4 e’s to zone on the perfect level of excitement.
If you leave off one of ends, it works as a greater than or less than. Here we are looking for squ followed by a minimum of 4 e’s
If you leave off one of ends, it works as a greater than or less than. Here we are looking for squ followed by a minimum of 4 e’s
Anchors constrain your match to a certain part of the string!
Caret means, at the beginning of the string. Don’t confuse it with the caret inside of brackets which means to negate. Here we are selecting the first ‘word’ in the string.
Dollar sign means at the end of the string and goes on the other end.
is the best one EVER. It means a word boundary (start or end of the string, surrounded by spaces or punctuation). Here we’re matching all words that start with ‘a’ - but don’t match ‘a’ in the middle of string. TODO: How to do this without word boundaries?
You can use it on both ends of your regex. Here we’re finding all words that are exactly three characters long.
Anchors constrain your match to a certain part of the string!
If you put something in parenthesis, you’re putting it into a match group or and storing the parenthesized content for later in a numbered slot
Why do you care about storing them? You can reference them again later in code. (TODO: Change to <blockquote> tag and use javascripts. Use rubular on a workspace.
If you use a pipe character, you can provide several options in a match group
If you want to group things without creating match groups, you can use a special syntax with a questionable colon. Provide example of nested matchgroup spaghetti and why you would want to use this.
Chances are if you know perl, you shouldn’t be here..
One gotcha with Java is that it doesn’t contain a native regular expression delimiter so you have to double escape things.