Nithin B
Nithin B

Reputation: 680

Regex expression to extract dates in text?

I have these following text.Few are selected and few are not.

Any 9/20/1993 [Selected]

Or 9/20/93 [Selected]

09.20.1993 [Selected]

09/20/1993 [Selected]

93/09/20 [Selected]

Wednesday 09/20/93 and done on 9/20/1993 12:00 AM [Not selected][In between text]

1993 - 09 - 20 [Not selected][white spaces not ignored]

9/20/1993 12:00 AM [Not selected]

Now I am using this: ([0-9]{1,4}[\s*(/?-?.?\)?\s*][0-9]{1,4}[\s*(/?-?.?\)?\s*][0-9]{1,4})$

How to select pattern in between and ignore white spaces?

Note: [] I put have reasons in it.

Upvotes: 0

Views: 208

Answers (2)

Nithin B
Nithin B

Reputation: 680

This one worked for me exactly.

(?i)([0-9]{1,4}[( /?-?.?\?)]{1,}[0-9]{1,4}[( /?-?.?\?)]{1,}[0-9]{1,4})

Here is the working example: https://regex101.com/r/aU9jH6/1

Modifying @Toto's expression: https://regex101.com/r/nB4bU2/1

Upvotes: 0

Toto
Toto

Reputation: 91430

Put the \s* outside of the character class and use word boundaries (\b):

\b(\d{1,2}\s*[/.-]?\s*\d{1,2}\s*[/.-]?\d{1,4})\b

Upvotes: 1

Related Questions