Will it matchWorksheet

I will stop at intervals to ask you to answer questions:

The string we are searching:

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

Set 1 – Single Characters and Dots:

Questions – will these match the string above? answer yes or no

1.1 A

1.2 and all

1.3 and shreds

1.4     . (tell what it matched first)

1.5  t.sh

1.6 t..sh

1.7 @

1.8 \. (Tell what it matched first)

Set 2 – Classes

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

2.1 [ozy]

2.2 [SHREDS]

2.3 [^ozy]a[sn]

2.4 [C-F]

2.5 [^\^]

Set 3 – Anchors

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

Note: a ^ inside [] means not, but outside [] means beginning of line

Reminder: ^ begin line; $ end line;  

3.1 ^t

3.2 [^t]

3.3 trash

3.4 trash$

3.5 com$

3.6 ^B

3.7 .$

Set 4 – Alternator  

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

·         Note that | in a regular expression means OR words on either site and | at end of unix command means pipe the output

·         note that characters inside [ ] are treated as individual character OR, while | set up OR for words

·         note that OR (|) takes is the strongest divider – so  c[de]|xy à c followed by d or e will match or xy will match.

4.1 trash|vacuum

4.2 vacuum|trash

4.3 what trash|vacuum

Set 5 – Repetition

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

Note that * in a unix command expands to include all matching filenames, while * in a regular expression means repeat the last character set zero or more times.

* - zero or more; + one or more; ? zero or one

{#,#} range of how many times repetition needed

5.1 t*sh

5.2 t*

5.3 t+

5.4 t?

5.5 o+

5.6 ta?[kr]

5.7 t.*sh

5.8 [^t]+

5.9 [s-u]+

5.10 Bro{2}k

5.11 r[oka]{1,4}

5.12 r[oka]{3}

5.10 @.*\.

5.11   [^ ]*@ (and note I put a space before the dot)

5.12    [^ ]*@.*\..* (and note a space before and after this expression)

5.13 ro*

5.14 (ro)*

Set 6 – BackRefs

Brooklyn takes the trash out of the can and shreds it all over the room. Email her at brook@baddag.com

note that a backref works with a group inside ( ). The first group's match is \1 and the second is \2

6.1 (.)\1

6.2 (.)(.)\2\1 (what will it match)

6.3 t(.).*\1 (what will it match)

--

Answers can be tested at http://www.zytrax.com/tech/web/regex.htm#positioning