python - Regex for word exclusion -
i'm trying write regex match first , third words in string:
term1 , term2
my first attempt [^(\s|(and))]+
, fails because
term1 anbd term2
gives me these 3 matches: ['term1','b','term2']
whereas want return ['term1','anbd','term2']
match first , third words: (\s+)\s+\s+\s+(\s+)
edit: if mean 'match words except word "and"' then: \b(?!and\b)\s+\b
Comments
Post a Comment