I'm using a straight forward regex pattern ('\s+') that is not ignoring white space?

For option one you wrote: result = regex. Search(line) if regex. Search(line): for option two you wrote: result = regex.

Search(re. Sub(r'\s+', '',line)) if regex. Search(line): If your have a result variable, then use it in your if-statement.

I'm sorry to say it, but you've got a copy-paste error here in my opinion For clarity if choice == '1': for root,dirname, files in os. Walk(directory): for file in files: if file. Endswith(".

Log") or file. Endswith(". Txt"): f=open(os.path.

Join(root, file)) for i,line in enumerate(f.readlines()): result = regex. Search(line) if result: # FIX 1 print " " print "Line: " + str(i) print "File: " + os.path. Join(root,file) print "String Type: " + result.group() print " " f.close() re.purge() if choice == '2': for root,dirname, files in os.

Walk(directory): for file in files: if file. Endswith(". Log") or file.

Endswith(". Txt"): f=open(os.path. Join(root, file)) for i,line in enumerate(f.readlines()): result = regex.

Search(re. Sub(r'\s+', '',line)) if result: # FIX 2 print " " print "Line: " + str(i) print "File: " + os.path. Join(root,file) print "String Type: " + result.group() print " " f.close().

For option one you wrote: result = regex. Search(line) if regex. Search(line): for option two you wrote: result = regex.

Search(re. Sub(r'\s+', '',line)) if regex. Search(line): If your have a result variable, then use it in your if-statement.

I'm sorry to say it, but you've got a copy-paste error here in my opinion. For clarity if choice == '1': for root,dirname, files in os. Walk(directory): for file in files: if file.

Endswith(". Log") or file. Endswith(".

Txt"): f=open(os.path. Join(root, file)) for i,line in enumerate(f.readlines()): result = regex. Search(line) if result: # FIX 1 print " " print "Line: " + str(i) print "File: " + os.path.

Join(root,file) print "String Type: " + result.group() print " " f.close() re.purge() if choice == '2': for root,dirname, files in os. Walk(directory): for file in files: if file. Endswith(".

Log") or file. Endswith(". Txt"): f=open(os.path.

Join(root, file)) for i,line in enumerate(f.readlines()): result = regex. Search(re. Sub(r'\s+', '',line)) if result: # FIX 2 print " " print "Line: " + str(i) print "File: " + os.path.

Join(root,file) print "String Type: " + result.group() print " " f.close().

I haven't tested it myself, but I think if regex. Search(line): should be if result.

1 This site is for providing answers, not guesses. Your answer would be much better and have a better chance of being accepted if you took a few moments to verify your statements. – Bryan Oakley May 1 at 14:29.

When you do this: result = regex. Search(re. Sub(r'\s+', '',line)) if regex.

Search(line): ... ... you are stripping out whitespace from line, and the result of that is being passed to regex.search(). The result of that search is stored in result. Then you ignore the result and perform the regex.search() on the unmodified original string.Re.sub() does not modify the original line, it returns a string that is the result of the substitution.

I'm not sure why this regex pattern ('\s+') is not ignoring whitespace: the code below searches all of the . Log files in a directory and returns the matched string entered by the user. It takes the string and converts it into hex and ASCII, then concurrently searches all .

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions