^((?!word).)*$
input:
word
test
one two
aword
output:
test
one two
Why is "aword" not there in output? I want the pattern to only match "word".
^((?!word).)*$
input:
word
test
one two
aword
output:
test
one two
Why is "aword" not there in output? I want the pattern to only match "word".
To remove all the occurrencies of the word word
you can use the following:
inp = 'word test one two aword'
inp2 = re.sub(r'\bword\b','',inp)
inp2:
' test one two aword'
In alternative you can put your words into a list and use list.remove()
inp2 = inp.split(' ')
inp2.remove('word')
inp2 = ' '.join(inp2)
inp2:
'test one two aword'
The regular expression you entered is correct!
'''^((?!word).)*$'''
There must probably be an error in the subsequent functions.
Try checking your regular expressions with online tools.