I have this regex which detects all words:
\b[^\d\W]+\b
And I have this regex to detect quoted texts:
\'[^\".]*?\'|\"[^\'.]*?\"
Is there a regex which can detect words which are not in quotes(both single and double)?
example:
import re
a = "big mouse eats cheese? \"non-detected string\" 'non-detected string too' hello guys"
re.findall(some_regex, a)
It should output this
['big', 'mouse', 'eats', 'cheese', 'hello', 'guys']
I know I can use re.sub()
to detect the quoted text and then replace it with a blank string but thats what I don't want to do.
I also looked up this page regex match keywords that are not in quotes and tried this (^([^"]|"[^"]*")*)|(^([^']|'[^']*')*)
but it didn't work A regex to detect string not enclosed in double quotes also tried this (?<![\S"])([^"\s]+)(?![\S"])|(?<![\S'])([^'\s]+)(?![\S'])
both detected all words