[Tutor] Learning Regular Expressions

DirkJSoren@gmail.com dirkjsoren at gmail.com
Mon May 30 13:21:49 EDT 2016


On 05/24/2016 01:48 PM, Alan Gauld via Tutor wrote:
> On 23/05/16 23:08, Terry--gmail wrote:
>
>> scripted worked great without the notes!  I'd like to know what it is in
>> the below Tripple-Quoted section that is causing me this problem...if
>> anyone recognizes. In IDLE's script file..._it's all colored green_,
>> which I thought meant Python was going to ignore everything between the
>> tripple-quotes!
> Its all green forv me too and it runs perfectly - as in it does
> absolutly nothing.
>
>
> And if I add print('hello world') at the end it prionts ok too.
>
> I even tried assigning your docsstring to a variable and printing
> that and it too worked.
>
> Linux Mint 17
> Python 3.4.3
> IDLE 3
>
> So I don't think this is your entire problem. Maybe you should
> show us some code that actually causes the error?
>
>> But if I run just the below portion of the script in
>> it's own file, I get the same While Scanning Tripple-Quotes error.
> As above, it runs silently for me.
>
Hi Alan,

I moved my notes that contained any '\'s to a different python file.
However, if we run it, we get the error I was having. Here's the
script:

#!/usr/bin/env python3

'''
Regular Expressions - or at least some

Identifiers:

\d  any number
\D  anything but a number (digit)
\s  space
\S  anything but a space
\w  any character
\W  anything but a character
.   any character (or even a period itself if you use \.) except for a 
newline
a   search for just the letter 'a'
\b  the white space around words

Modifiers
{x}    we are expecting "x" number of something
{1, 3}  we're expecting 1-3 in length of something -, so for digits we 
write  \d{1-3}
+  means Match 1 or more
?  means Match 0 or 1
*   Match 0 or more
$  Match the end of a string
^  Match the beginning of a string
|   Match either or   - so you might write  \d{1-3} | \w{5-6}
[ ]  a range or "variance" such as [A-Z] or [A-Za-z] Cap 1st letter 
followed by lower case
             or [1-5a-qA-Z] starts with a number inclusive of 1-5 then 
lower case letter then
             followed by any Cap letter! :)

White Space Characters  (may not be seen):
\n  new line
\s  space
\t   tab
\e  escape
\f  form feed
\r  return

DON'T FORGET!:
.  +  *  ?  [  ]  $  ^  (  )  {  }  |  \   if you really want to use 
these, you must escape them '\'

'''




More information about the Tutor mailing list