I’m using Python and trying to fetch an XML file from a list of files using regular expressions, but I’ve never used regular expressions until now.
Suppose I had a list of files:
files = ['.bash_logout', '20120910NYP.xml', '.bash_profile', '.bashrc', '.mozilla', 'testfile_248.xml']
Now I need to fetch the file of format 20120910NYP.xml so I decided to write a regular expression:
import re
feedRegex = # ?
feedFiles = filter((lambda x: re.search(feedRegEx, x) != None), files)
In the above code, how would I write a regular expression for feedRegex to find XML files in that format from the list?
Edited Code:
Need to give list of files and feedregex code to this function every time i need this function
import re
def paramikoFetchLatestFeedFile(list_of_files, feedRegEx):
self.files = list_of_files
self.feedRegEx = feedRegEx
feedFiles = filter((lambda x: re.search(self.feedRegEx, x) != None), self.files)
Obviously you want something like
Please read the regular expressions documentation. This is truly regex basics.