Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RegEx Match Anything Not in a Specific Expression

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading