Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Python Regular Expressions

You're reading from   Mastering Python Regular Expressions For Python developers, this concise and down-to-earth guide to regular expressions

Arrow left icon
Product type Paperback
Published in Feb 2014
Publisher Packt
ISBN-13 9781783283156
Length 110 pages
Edition Edition
Languages
Arrow right icon
Toc

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 "|".

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...

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 $19.99/month. Cancel anytime
Banner background image