I’m a bit confused, a regex pattern works fine but not in python. What am I doing wrong ?
In this works well
Stile = re.compile(r'(^\d{4} (?!Cadempino)[A-Z])([^0-9]*)')
if Stile.match(line):
Stile_no = line
print(Stile_no)
- 9643 BEIGE EBONY/COCOA 2 6 10 10 10 2 2 42 200.00 8,400.00
- 1000 NERO 0 0 2 6 10 10 10 2 2 42 218.00 9,156.00
- 1000 BLACK 0 0 0 2 6 15 15 15 2 2 0 0 57 205.00 11,685.00
- 1000 BLACK 2 2 2 2 2 1 11 218.00 2,398.00
- 9769 B.EBONY/NERO 3 3 3 3 3 1 16 244.00 3,904.00
But if i use python i get all strings. my goal is exactly the one shown below
>Solution :
Looking at your code you probably want to get rid off the matching groups and just print matching group 0:
import re
txt = '''\
6814 Cadempino Door: NUGNES 1920 MENS (TRANI)
411924 KGDHN MBELT W.40 INT. T.GG SUPREME/SELLERIA
9643 BEIGE EBONY/COCOA 2 6 10 10 10 2 2 42 200.00 8,400.00
406831 DJ20N MBELT W.40 GG MAR DOLLAR PIGPRINT
1000 NERO 0 0 2 6 10 10 10 2 2 42 218.00 9,156.00
414516 0YA0G MBELT W.30 GG MAR. PLUTONE CALF
1000 BLACK 0 0 0 2 6 15 15 15 2 2 0 0 57 205.00 11,685.00
406831 0YA0G MBELT W.40 GG MAR PLUTONE CALF
1000 BLACK 2 2 2 2 2 1 11 218.00 2,398.00
627055 92TIN MBELT W.37GG M.R T.GG SUPREME/PLUTONE CALF
9769 B.EBONY/NERO 3 3 3 3 3 1 16 244.00 3,904.00'''
Stile = re.compile(r'^\d{4} (?!Cadempino)[A-Z][^0-9]*')
for line in txt.splitlines():
m = Stile.match(line)
if m:
print(m.group(0))
Prints:
9643 BEIGE EBONY/COCOA
1000 NERO
1000 BLACK
1000 BLACK
9769 B.EBONY/NERO
