RegEx Match Anything Not in a Specific Expression

Advertisements

I currently have a very specific RegEx for use in identifying dates as yyyy/mm/dd

[0-9]{4}\/[0-9]{2}\/[0-9]{2}

Which works fine for my needs when identifying dates in text but I was wondering how I can use a similar RegEx to match everything that is not a date

The current one when using Date 1980/01/01 will match 1980/01/01

But now I need it when using Date 1980/01/01 to match Date

UPDATE

To better illustrate what I am trying to achieve I have a very basic RegEx that matches all standard letters

[a-zA-Z]

When using abcDEF123 it will match abcDEF

The inversion of it would be

[^a-zA-Z]

When using abcDEF123 it will match 123 (anything that is not a standard letter)

>Solution :

/(?<=What you don’t want)(What you want)

A positive lookbehind

|

OR

(What you want)(?<=What you don’t want)/

positive lookahead.

(?<=[0-9]{4}\/[0-9]{2}\/[0-9]{2})(.)+|(.)+(?=[0-9]{4}\/[0-9]{2}\/[0-9]{2})

https://regex101.com/r/vTTdcw/1

Leave a ReplyCancel reply