# public gastlygem /lrethw-cn

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

file 51 lines (38 sloc) 1.769 kb
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \chapter{Exercise 5: Inverting Sets Of Characters}Well, it's probably not a good idea to offend Cthuhlu, so we actually wantto match every line that \emph{does not} have vowels. Normally that wouldinvolve you writing out all of the characters that don't match, which istedious and dumb. Instead, you can invert the set by putting a \verb|^| (caret)as the first character inside the set.\begin{code}{ex5.regex}\begin{Verbatim}<< d['code/ex5.regex'] >>\end{Verbatim}\end{code}To make this work I have to switch to !match mode, which will actuallymatch the first character. I also have to use a more complete "vowels"set since I didn't have capital letters in the previous exercise. Onceyou have that, put the \verb|^| at the front and it will now be an inverseset.\section{What You Should See}When you run this it should only print the thing Cthuhlu said:\begin{code}{ex5 Output}\begin{Verbatim}<< d['code/ex5.regex|regetron']['ex5.txt'] >>\end{Verbatim}\end{code}There's something else you might have missed in the last exercise.The above character set is matching \emph{one} character, but you canmake a regex that is two sets and it will match one, then the next.You could do \verb|[a-z][A-Z][0-9]| and that would match, "A lowercaseletter followed by an uppercase letter followed by a number."\section{Extra Credit}\begin{enumerate}\item Create another class that is "everything except X" so that it    doesn't match Cthulhu's line.\item Go back and update your phone number matching regex so that it's    "not letters" instead.\end{enumerate}\section{Portability Notes}Some regex engines don't have this feature. Those regex engines sucksince it's a trivial thing to implement and is a commonly needed operation.
Something went wrong with that request. Please try again.