Saturday 15 March 2014

if statement - Python 3: Regex matching 2 seperate conditions -


I'm just trying to do the best thing to print the numerical lines, the code is only partially completed Because I'm still new to regex in general so the correct method or syntax can not be used; Different reminds work fine, this is when I add them that I get unwanted results: / P>

Sample string:

  Hail = 'title | Head 1 | Head 2 | Head 3 | Head 4 ---- | ------ | ----- | ----- | 1 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none) 2 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none) 3 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none) 4 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none) 5 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, None) All | Processes: | MemAlloc | = | 408125440 | (None, none). 0.0.0.0 | (None, none) 0.0.0.0, Re-import '' 'for line in file: pat = re.match (' (^ [AZ] [az]) | (^ -. +) ', Line) Use # or re.match ('^ [0-9]', line) and match Pat! = None Patip = re.match ('^ {1,3} \. \ D {1,3} \. \ D {1,3} \. \ D {1,3}', line) # if Patip == None and abdomen == None: Print (line)   

I am stuck to print counting lines on logic. I can be completely closed Keep in mind .. I do not want to print the line 0.0.0.0 (IP address).

Desired output:

  1 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none) 2 | 1,150,976 | 0 | 25,300,992 Bfa92720 / beefa 9 24f8 Su (None, none) 3 | 1150 976 | 0 | 25300992 | Bifa 92720 / BIFA 924F8 | Su (None, none) 4 | 1150 976 | 0 | 25300992 | Beef 927 20 / bfa924f8 | Su (None, none) 5 | 1,150,976 | 0 | 25,300,992 Bfa92720 / bfa924f8 Su (None, none)  

Import import import sys file = Io.StringIO ('' 'title | head1 | head2 | head3 | head4 | ---- | ----- - | ----- | | ----- | 1 | 1,150,976 | 0 | 25,300,992 | bfa92720 / Bfa924f8 | su ((none, none) 2 | 1,150,976 | 0 | 25,300,992 | bfa92720 / bfa924f8 | su (none, none) 3 | 1,150,976 | 0 | 25,300,992 | bfa92720 / bfa924f8 | su | (none, None) 4 | 1,150,976 | 0 | 25,300,992 | bfa92720 / bfa924f8 | su (None, none) 5 | 1,150,976 | 0 | 25,300,992 | bfa92720 / bfa924f8 | (none, none) All | Processes: | MemAlloc | = | 408125440 | (none, c (No, None) 0.0.0.0, Text '' ') sys.stdout.writelines (If file re.match (' \ d + | ', line))

No comments:

Post a Comment