SparkNee
SparkNee

Reputation: 460

Regex selecting date delimiter

How to select the delimiters of a date strictly with a regex?

I'm using this: (\W)(?=(dd|MM|yyyy))

And I'm taking this example: dd/MM/yyyy HH:mm:ss

But when I had any spaces in front of a dd for example I'm getting that, how can I scape this, in other words, how can I create an exception in\W to not catch spaces?

Upvotes: 1

Views: 132

Answers (1)

Joost
Joost

Reputation: 3209

Maybe you can filter non-whitespace \S instead of a word. Ofcourse this means that spaces can no longer be used as a delimiter.

(\S)(?=(dd|MM|yyyy))

This works for your example with a space before the date

 dd/MM/yyyy HH:mm:ss

Upvotes: 2

Related Questions