Regex: Match a pattern but exclude one case

regex, regex-lookarounds, regex-negation

Solution

Use a Negative Lookahead here. If you want to match all strings that begin with `a` through `m` excluding the strings that begin with "deal_string", you can use:.

^(?!deal_string)[a-m].*$

Live Demo

Problem

I want to include all strings starting from a to m. This can be done using [a-m]* regex but I don't want a case where the string starts with "deal_string". What is the regular expression for this? Test cases: ``` assets/filename.ext -> pass deal_string/filename.ext -> fail deal_string.ext -> fail deal_string_1.ext -> fail deal_draft.txt -> pass assets_deal_string.txt -> pass bombay.txt -> pass zombie.srt -> fail some_deal_string.txt -> fail zobie_special_string.txt -> fail ```

Original source

Related problems