About the Tutorial


re provides full support for Perl-like regular expressions in Python. The  re



Download 2,85 Mb.
Pdf ko'rish
bet226/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   222   223   224   225   226   227   228   229   ...   234
Bog'liq
python3 tutorial 060821094426

re
provides full support for Perl-like regular expressions in Python. The 
re
module raises the exception 
re.error
if an error occurs while compiling or using a regular 
expression. 
We would cover two important functions, which would be used to handle regular 
expressions. Nevertheless, a small thing first: There are various characters, which would 
have special meaning when they are used in regular expression. To avoid any confusion 
while dealing with regular expressions, we would use Raw Strings as
r'expression'

Basic patterns that match single chars 

a, X, 9, <
 
-- ordinary characters just match themselves exactly. 

. (a period)
-- matches any single character except newline '\n' 

\w
-- matches a "word" character: a letter or digit or underbar [a-zA-Z0-9_]. 

\W
-- matches any non-word character. 

\b
-- boundary between word and non-word 

\s
-- matches a single whitespace character -- space, newline, return, tab 

\S
-- matches any non-whitespace character. 

\t, \n, \r
-- tab, newline, return 

\d
 
-- decimal digit [0-9] 

^
 
= matches start of the string 

$
 
= match the end of the string 

\
-- inhibit the "specialness" of a character. 
Compilation flags 
Compilation flags let you modify some aspects of how regular expressions work. Flags are 
available in the 
re
module under two names, a long name such as 
IGNORECASE
and a 
short, one-letter form such as I. 
Flag 
Meaning 
ASCII, A 
Makes several escapes like \w, \b, \s and \d match only on ASCII 
characters with the respective property. 
DOTALL, S 
Make, match any character, including newlines 
IGNORECASE, I 
Do case-insensitive matches 
20.
 
Python 3 – Regular Expressions 


Python 3 
347 
LOCALE, L 
Do a locale-aware match 
MULTILINE, M 
Multi-line matching, affecting ^ and $ 
VERBOSE, 

(for 
‘extended’) 
Enable verbose REs, which can be organized more cleanly and 
understandably 

Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   222   223   224   225   226   227   228   229   ...   234




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish