Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Python Regular Expressions

You're reading from  Mastering Python Regular Expressions

Product type Book
Published in Feb 2014
Publisher Packt
ISBN-13 9781783283156
Pages 110 pages
Edition 1st Edition
Languages

Compilation flags


When compiling a pattern string into a pattern object, it's possible to modify the standard behavior of the patterns. In order to do that, we have to use the compilation flags. These can be combined using the bitwise OR "|".

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}

Flag

Python

Description

re.IGNORECASE or re.I

2.x

3.x

The pattern will match lower case and upper case.

re.MULTILINE or re.M

2.x

3.x

This flag changes the behavior of two metacharacters:

  • ^: Which now matches at the beginning of the string and at the beginning of each new line.

  • $: In this case, it matches at the end of the string and the end of each line. Concretely, it matches right before the newline character.

re.DOTALL or re.S

2.x

3.x

The metacharacter "." will match any character even the newline.

re.LOCALE or re.L

2.x

3.x

This flag makes \w, \W, \b, \B, \s, and \S dependent on the current locale.

"re.LOCALE just passes the character to the underlying C library. It really only works on bytestrings which have 1 byte per character. UTF...