Search code examples
c#regexdatenumbers

Regex that include numbers but exlude numbers in dates (xx/xx/xx)


I currently only have the regex that matches all numbers. But I also want to exlude numbers that are in dates

Exlude numbers that are in dates -> 08/11/2022. But include numbers without date.

This is my regex: \d+


Solution

  • What differentiate dates and numbers is existence of '/' or '-'. So, you can use negative lookhead after your pattern and negative lookbehind before your pattern.

    (?<![\d\-\/])\d+(?![\d\-\/])
    

    Check on Regex101