regex - Using regular expressions to match a word in Python -


I am using PRAW to create a reddit bot which says "alot" and a list of their username . I have trouble with regular expressions and how the string works. This is my code.

imported import time of import time for Red Eddy API and time to import user name = "Louise Theobot" password = R = PRA. Readout (User_Agent = "People are counted (" Test ") Print (" Grabbing Srreded ") Comments: (which" say a lot ") word_to_match = ['\ balot \ b'] storage = [] r. Login (username, password) def run_bot (): subreddit = r.get_subreddit = subreddit.get_comments (limit = 200) print ("comment drag") for comment in comment: comment_text = comment.body.lower () hasmach = Anyone (string for string in word_to_match in string) if comment.id is not in storage and IsMatch: print ("Match got!" Name: "+ str (comment.author) +" storage in the list.) Storage.append (comment.author) print ("Currently:" + str (lane (storage)) "People who have 'a lot' Instead of using 'lots'.) While correct: run_bot () time.sleep (5)

So I'm a regular expression, as a part of a string, many words Instead of looking for a lot of words, example ze too many whenever I run it, it will not get any comments that I have made. Any suggestions?

You are checking with string operation, not In

  isMatch = any (string for string for string in word_to_match)  

first in here is a substrings There is nothing to do with RS.

In addition, there is an error in your start:

  word_to_match = ['balot \ b']  

'b' Code code is 0x08 (backspace). To avoid such a trap, use the raw string syntax for always RE pattern:

  word_to_match = [r '\ balot \ b']  

Now you have two letters, backslash then b , which will interpret the meaning of RE "word boundary".

There may be other bugs but I do not try to see more than two bugs per question ...: -)


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -