while ( <DATA> ) { s!\b((\d{4}[-/]\d{2}[-/]\d{2}\b)|(\d{2}[-/]\d{2}[-/]\d{4}))\b!<date +>$1</date>!g; print; } __DATA__ 2000-04-23 was a great day, but 04-24-1999 is much better. 2000/04/23 I would like to match those 3 formats for now. 2000-85-85 is not a real date.
The above regex does what you ask, but as noted by fellow monks, if you do not use a module, you will need to add other things to make sure what it is that you are matching is trully a date. As the above regex will accept 2000-73-08 which is not a valid date. One could write a regex to eliminate this possiblity, but as FamousLongAgo mentions there are vast subtleties as to what might be a valid date. (leap years, as one example,present a special problem). But then again only you know the data you are trying to match against.
As previously mentioned by saouq, if you give a better explanation of why don't want to use a module and what else you might need, someone will lead you in the right direction.
In reply to Re: Re: Re: matching different date formats
by Enlil
in thread matching different date formats
by imlou
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |