This is as much for me as a note for the future as it is a tip to share :)
In my scripts I had a problem where I was using the Python String .find() method.
This worked great unless the word you were looking for was commonly found within other common words.
As an example, I would look for "Thor" and find "Author" matched.
(Hence the silly photoshop above!)
For a long time I avoided Regex in Python because in my past with PERL and C# I had done enough of it for data validation that the thought made me roll my eyes into the back of my head.
Seems, however, Python's implementation is not as painful as I feared it would be.
While you can compile a regex object, like so:
re.compile("myregex.*")
You can also pass the regex to the search, saving me having to compile and recompile my regex for each keyword in my loop.
It also returns None or an object, which in an If statement does translate as True or False, but you can wrap it in Bool() if you need True or False returned.
Here is how my If turned out:
if re.search(r"\b{}\b".format(needle), haystack, re.I):
post_url = "/@{}/{}".format(author, permlink)
Here I am looking for my word (needle) surrounded by word boundaries in the returned sentence (haystack), ignoring case sensitivity.
So now I don't find authors when looking for Thor!*