You are on page 1of 5

Bookmarks Capitolul 7 - Modul…  2. Mod…  Clase d…

Search

 Formalitati Clase de caractere speciale (coduri de


pentru sedinta evadare)
1 de curs
Clase de caractere speciale (coduri de evadare)

 Cursanti            \d - digit


Online - Reguli \D - non-digit
de Promovare \s - whitespace (tab, space, newline, etc.)
\w - alphanumeric

 Capitolul 1 - \W - non-alphanumeric
Introducere în
limbajul
Python
Ancorare
 Capitolul 2 -
Operatori și Pe lângă descrierea conținutului unui șablon care se potrivește,
structuri de puteți specifica locația relativă în textul de intrare unde modelul
control ar trebui să apară utilizând instrucțiunile de ancorare.

 Capitolul 3 - ^ - început de string sau linie


Tipuri $ - sfârșit de string sau linie
avansate de \A - începutul unui string
date \Z - sfârșitul unui string
\b - empty string at the beginning or end of a word
 Capitolul 4 - \B - empty string not at the beginning or end of a word
Funcții și
excepții

 Examen Parțial Creați un program cu codul de mai jos care folosește regexp de mai
sus:
import re
 Capitolul 5 -
text = 'Acesta este un text unde o sa cautam un cuvant in tot textul.'
Lucrul cu
pattern = re.compile(r'\b\w*text\w*\b')
fișiere &
print('Text:', text)
examen parțial
print

pos = 0
 Capitolul 6 -
while True:
Lucrul cu
memoria și   match = pattern.search(text, pos)

module   if not match:

externe       break

  s = match.start()

 Capitolul 7 -   e = match.end()

Module în   print('  %2d : %2d = "%s"' % \

Python       (s, e-1, text[s:e]))

  # Move forward in text for the next search


1. Modulele SYS și   pos = e
OS

2. Modulul RE
(expresii
regulate) Match.group - regexp grouping

3. Modulul
Random

4. Arhivarea și Creați un program numit match_group.py cu codul de mai jos:


dezarhivarea de
import re
fișiere
text = 'This is some text -- with punctuation.'
Materiale Video print(text)

Examen Capitol 7 print


Examen de capitol  for pattern in [ r'^(\w+)',           # word at start of string

Download                r'(\w+)\S*$',        # word at end of string, with optional punctuation

materiale curs                r'(\bt\w+)\W+(\w+)', # word starting with 't' then another word

               r'(\w+t)\b',         # word ending with 't'

 Capitolul 8 -                ]:

Programare   regex = re.compile(pattern)

obiect   match = regex.search(text)

orientată   print('Matching "%s"' % pattern)

  print('  ', match.groups())


  print
 Capitolul 9 -
Programare
obiect
orientată
(continuare)
/usr/bin/python3.5 "/home/pandelegeorge/projects/telacad/sedinta
6/re_groups_match.py"
 Examen Final This is some text -- with punctuation.
Matching "^(\w+)"
 Exercitii   ('This',)
suplimentare Matching "(\w+)\S*$"
  ('punctuation',)
Matching "(\bt\w+)\W+(\w+)"
  ('text', 'with')
Matching "(\w+t)\b"
  ('text',)
Process finished with exit code 0

Creați un program care să facă individual grouping regexp

import re

text = 'This is some text -- with punctuation.'

print('Input text            :', text)

# word starting with 't' then another word

regex = re.compile(r'(\bt\w+)\W+(\w+)')

print('Pattern               :', regex.pattern)

match = regex.search(text)

print('Entire match          :', match.group(0))

print('Word starting with "t":', match.group(1))

print('Word after "t" word   :', match.group(2))


/usr/bin/python3.5 "/home/pandelegeorge/projects/telacad/sedinta

6/grupuri_individuale.py"

Input text            : This is some text -- with punctuation.

Pattern               : (\bt\w+)\W+(\w+)

Entire match          : text -- with

Word starting with "t": text

Word after "t" word   : with

Process finished with exit code 0

IGNORECASE sau i

MULTILINE sau m

Creați programul de mai jos si rulați-l

import re

text = 'This is some text -- with punctuation.'

pattern = r'\bT\w+'

with_case = re.compile(pattern)

without_case = re.compile(pattern, re.IGNORECASE)

print('Text            :', text)

print('Pattern         :', pattern)

print('Case-sensitive  :', with_case.findall(text))

print('Case-insensitive:', without_case.findall(text))
/usr/bin/python3.5 "/home/pandelegeorge/projects/telacad/sedinta

6/case_insensitive_matching.py"

Text            : This is some text -- with punctuation.

Pattern         : \bT\w+

Case-sensitive  : ['This']

Case-insensitive: ['This', 'text']

Process finished with exit code 0

You might also like