Search code examples
regexasp-classic

How do I match [Any Character Except X] in a regular expression?


Is there are way to do this?

So if X is the unwanted character, I'd be looking for something like (.*[^X])

The aim is to match every character in a string until an X turns up.

I've searched high and low, but can't find the answer.


Solution

  • To match everything up to a certain character X, the simplest should be;

    [^X]*
    

    Simple refiddle to show it.