create regex for several matches -
I will test the date string to see if it is one of three: dd-mm-yyyy OR yyyy Or dd-mm-yyyy / dd-mm-yyyy
I have combined these three, but the last one causes problems because I just \ "\" / \ \ \ / \ / \ \ Previous> 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}) [0- 9] {2} - [0- 9] {2} - [0- 9] {4} - & gt; Dd-mm-yyyy [0- 9] {4} - & gt; Yyyy [0- 9] {2} - [0- 9] {2} - [0- 9] {4} \ Q / \ E [0- 9] {2} - [0- 9] {2} - [0- 9] {4} - & gt; Combined expression:
([0- 9] {2} - [dd-mm-yyyy / dd-mm-yyyy
Question 1: How to make a single " / "Is allowed between dates?
Question 2: Finally what does a regex and $ mean at the beginning? And I should have it in me
Br Anders
UPDATE: (based on replies and comments) Thanks! Two correct answers I marked the last one because there was a very easy way of writing that I tried to do.
The language is probably XSLT or C #. It is in CMS Umbraco that I impose a regex to validate a default text string / input field.
This works a little funny.
This string works perfekt: ^ (?: \ D {4} | \ d {2} - \ d {2} - \ D {4} (?: / \ D {2} - \ d {2} - \ d {4})? $$
Since you have not specified a language, I can suggest the Perl version:
/ ^ (?: \ D {4} | \ D {2} - \ d {2} - \ d {4} (?: \ / \ D {2} - \ d {2} - \ d {4})?) $ /
<Pattern explained:
- Start on the first letter of the string
- 4 digits (
\ d {4}
Two digits of two digits dash two digits dash f Alternatively,
a slash two digit
I have literally written
/
- > / code> typing
\ /
is the most cross-language way to do this: to avoid the need to avoid it in Pearl Individual patterns will be enough to choose the delimiter.
Comments
Post a Comment