Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
peter keves6,854 Points
verbose/multiline string / /b world boundery
1) verbose 2) multiline string 3) \b world boundery
can someome expain to me those terms ?
Verbose as it applies to python regular expressions means that both white space and comments are ignored. This makes it much more readable. Without the verbose flag it would be compacted together with no white space and no comments making it much more difficult to read. In python in general we are encouraged to white verbose code so that readability is at it's maximum.
multi-line string begins and ends with triple quotes (i.e. `'''). This allows us to write a string that takes up as many lines as we need. You can see Kenneth Love using this with the verbose flag so that he can break up a regular expression into smaller chunks.
A word boundary means either the beginning or end of a word. This can be based off of white space, the beginning of a new line or the end of a line. So
\bfoo will match
foo bar and
bar foo, but not
foo\b will match
foo bar and
bar foo and
barfoo, but not
Hope this makes sense.
Yes - the verbose flag allows us to add white space (which is usually not ignored in regex) and comments without altering how the regular expression functions. Generally regular expressions look awful and are difficult to read and interpret. The verbose flag allows us to break this apart and add comments so that other's (or ourselves down the road) will be able to understand what is going on.