Tag Archives: regex
Python – Filter directory contents
short and sweet, this python snippet will return a list containing your filtered directory import re import os filter = “.*” + searchstr + “.*” m = re.compile(filter,re.I) #if you want to ignore case use re.I, otherwise remove it filter(m.search,os.listdir(os.getcwd())) … Continue reading
Python – Use regex to split hyphenated words
I was asked this question on stackoverflow, and figured I’d repost it here since I wrote it after all. s = “-this is. A – sentence;one-word what’s” re.findall(“\w+-\w+|[\w']+”,s) result: ['this', 'is', 'A', 'sentence', 'one-word', "what's"] make sure you notice that … Continue reading
Python – Chunk string or data buffer
I was disappointed that there was no good way to chunk up data for string formatting or packetzing UDP data. After a bit of thought, and a desire to avoid using python code to do loops, I came up with … Continue reading