   Python. 24    
 


  ,    Python    ,    . 24 :  ,  , Unicode, , ,  ,    .      ,  ,     ,   .   :            CSV    .   ,        Python. ,        .





 

   Python. 24    





  ,     


  ,   ,        .       ,   ,   :    ,        .           .

  24   .        .       :  ,  ,      .       ,      .

   Python: , ,    .     .    [ for  in ]       .   ,      regex.       .

  .      ,         .       .          -    .




    


   Python 3.12.       python.org.   : re, csv  io    .       task.py,    ,   UTF-8   python3 task.py.  ,    ,    Python 3.     ,   .

    .          .          .         :         .      ,    ,     .        .      ;        Enter.

      .                     .       .      :       .

 text   .     samples   . Pattern  , result   . Print(repr(result))   :       \n,    \t.      ,    .         .

    raw-   r  . , r'\b'   re      b,      Python-. Raw-    regex:          Python.

    .    ,          .         .      ;          .




    


Fullmatch   ,     . Search      - . Findall   ,       .            .

      fullmatch.         .     sub.      ,    ,        .

        .       ,       ,      . Regex     ,    -   .




 1.    


  :    ,     ASCII-. ,      .  True  False    samples;       .




import re

samples = ['AB-0042', 'ab-0042', 'AB-0042x', '', 'AB-123']

pattern = r'[A-Z]{2}-[0-9]{4}'

result = [re.fullmatch(pattern, s) is not None for s in samples]

print(repr(result))


 

[True, False, False, False, False]

    ,    . [A-Z]{2}       ,       .       .

  fullmatch,     . Search    AB-0042            .    :    ,     .


 

samples = ['ZZ-9999', ' AA-0001', 'AA-0001\n']

 :

[True, False, False]




   ^  $     fullmatch?




,       .         .




 2.  ,     


    INV-   ASCII-.  ,      ,     .      .       .




import re

text = 'INV-0042; XINV-0042; INV-00421; (INV-0700); INV-0001_extra'

pattern = r'(?<!\w)INV-[0-9]{4}(?!\w)'

result = re.findall(pattern, text)

print(repr(result))


 

['INV-0042', 'INV-0700']

   (?<!...)      ,  (?!...)  .       .     slash  .

   Python  \w  Unicode-,   .     ,     .       ,       .


 

text = 'INV-1234 INV-5678'

 :

[]

text = 'INV-0000/INV-0001'

 :

['INV-0000', 'INV-0001']

text = ''

 :

[]




       INV-0042  INV-00421?




    ,          .    .




 3.  ASCII-  Unicode-


  :       Unicode      09.    -   .     ,     .




import re

samples = ['123', '???', '???', '12A']

result = ([re.fullmatch(r'\d{3}', s) is not None for s in samples], [re.fullmatch(r'[0-9]{3}', s) is not None for s in samples])

print(repr(result))


 

([True, True, True, False], [True, False, False, False])

  \d      ASCII 09.  Unicode- Python     Unicode.      ,   ,    :       .

   .        .   ,     ASCII,    .           .


 

samples = ['000', '???', '']

 :

([True, False, False], [True, False, False])




        ,    ASCII?




  .       Unicode.       .




 4.    


   a+b.txt  .        ,    regex.      ,          .




import re

text = 'a+b.txt ab.txt aaabXtxt a+b.txt'

needle = 'a+b.txt'




  .


   .

   ,     (https://www.litres.ru/book/raznoe/reguliarnye-vyrazheniia-na-python-24-zadachi-s-proverkoi-rezul-tata-74417008/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


