Python regex to find words, which also excludes particular words -
i'm new programming. i've searched site , google, can't seem resolve issue. i'm finding similar topics, still can't figure out...
i have text file containing large list of words. words numbered , categorized 'noun', 'adjective' or 'verb'.
i'd extract words list, exclude numbers , following 3 words, 'noun', 'adjective' , 'verb.'
i know need use caret character, can't seem make work.
import re import os textfile = open('/users/mycomputer/wordlist.txt') textfilecontent = textfile.read() wordfinder = re.compile(r""" [a-z]+ # finds words [^noun|adjective|verb] # wrong """, re.verbose | re.i) regexresults = wordfinder.findall(textfilecontent)
import re open('wordlist.txt') f: line in f: if re.search("^(?!noun|adjective|verb|\d)", line): print(line)
Comments
Post a Comment