Skip to main content

Posts

Showing posts from January, 2018

Python regex finditer

Just a revision for me, sharing with you all! so i have problem to find multiple keywords in a text. i tried using re.search. but that wouldnt work. as re.search only applicable if keyword found first in a group match. so, lets go ahead! i ran using python2.7 Example code for find keywords appearance using python re.finditer (regex) search_keywords = ["smart", "high", "confident", "mature"]  Now we join the keywords with OR operator | , it will looks something like this  smart|high|confident|mature search_patterns = "|".join(search_keywords) Sample input text text = "This is a story about a girl. Living in a secluded area in Wonderland.\n" \        "She is small but very smart and smart, how ever she has verly low confident. Dont judge a book" \        "by its cover.\n The way she thinks shown how mature she is."  Now we update the pattern again with ( ) - > parenthesis  The object