Your understanding of character-set negation is flawed. The regex [^p]
will match any string that has a character other than p
in it, which is all of your strings. To "negate" a regex, simply negate the condition in the if statement. So:
import re
someList = ['python', 'ppython', 'ython', 'cython', '.python', '.ythop', 'zython', 'cpython', 'www.python.org', 'xyzthon', 'perl', 'javap', 'c++']
pattern = re.compile('p')
result = []
for word in someList:
if not pattern.search(word):
result.append(word)
print result
It is, of course, rather pointless to use a regex to see if a single specific character is in the string. Your second attempt is more apt for this, but it could be coded better:
result = []
for word in someList:
if 'p' not in word:
result.append(word)
print result