Python Programming for Biology: Bioinformatics and Beyond


Appendix 5 Regular expressions



Download 7,75 Mb.
Pdf ko'rish
bet480/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   476   477   478   479   480   481   482   483   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Appendix 5

Regular expressions

The  term  ‘regular  expression’  refers  to  the  specification  of  a  particular  pattern  of

characters which may occur within a text string. Given a pattern a program can then look

for certain kinds of character being present in particular locations. As an example we may

wish  to  search  for  email  addresses  within  a  larger  piece  of  text.  In  reality  this  is  fairly

complex,


1

 but  the  basic  pattern  for  this  would  consist  of  a  leading  group  of  (mostly)

alphanumeric  characters,  without  spaces,  before  the  ‘@’  symbol,  then  more  characters

before  ending  with  a  dot  ‘.’  and  a  final  group  of  letters.  Such  a  pattern  would  expect  to

identify strings like ‘mickey@disney.com’ or ‘h.j.simpson@springfield.ac.uk’.

In  practice,  regular  expressions  in  Python  are  specified  using  a  system  where  special

codes are used to represent general or ambiguous kinds of character (it is actually a very

similar  system  to  what  is  used  in  other  languages  like  Perl  and  C).  For  example,  ‘\d’  is

used  to  match  any  digit  character  in  the  range  ‘0’  through  to  ‘9’.  Given  a  regular

expression  the  essential  task  is  to  determine  whether  a  pattern  does  or  does  not  occur

within  a  string.  If  it  does,  often  we  will  also  want  to  extract  the  substrings  that  matched

and perhaps replace them with some other text. It should be noted that some simple text

string queries and manipulations, which certainly could be done with regular expressions,

are  often  more  easily  performed  using  the  standard  string  methods.  Thus,  when  dealing

with  only  a  few  exact  substrings  we  recommend  considering  string  methods  like

text.find(subString), text.replace(old, new) in preference to regular expressions.




Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   476   477   478   479   480   481   482   483   ...   514




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