Hi
I shall test a date string to see if it is one of these three: dd-mm-yyyy OR yyyy OR dd-mm-yyyy/dd-mm-yyyy
I have combine these three, but the last one makes trouble since I cannot just match a single "/" using \Q/\E.
[0-9]{2}-[0-9]{2}-[0-9]{4} -> dd-mm-yyyy
[0-9]{4} -> yyyy
[0-9]{2}-[0-9]{2}-[0-9]{4}\Q/\E[0-9]{2}-[0-9]{2}-[0-9]{4} -> dd-mm-yyyy/dd-mm-yyyy
Combined they will give this expression:
([0-9]{2}-[0-9]{2}-[0-9]{4}|[0-9]{4}|[0-9]{2}-[0-9]{2}-[0-9]{4}\Q/\E[0-9]{2}-[0-9]{2}-[0-9]{4})
Question 1: How to only allow a single "/" between the dates?
Question 2: What does a ^ mean in the start of a regex and $ in the end? And should I have it in mine
Br. Anders
UPDATE: (based on answers and comments below) Thanks! Two right answer. I marked the last one right since there also was a much smoother way to write what I had tried to do.
Language is probably XSLT or C#. It is in the CMS Umbraco that I place a regex to validate a default texstring/input field.
It acts a bit funny. There is no difference if I add a ^ to the start, therefore my question about that.
This string works perfekt: ^(?:\d{4}|\d{2}-\d{2}-\d{4}(?:\/\d{2}-\d{2}-\d{4})?)$