Regular expression to match month number 1,...,12 (including e.g. 04,05) - Help
This is a discussion on Regular expression to match month number 1,...,12 (including e.g. 04,05) - Help ; How does a regular expression look like which should match exactly one of the
twelve possible month numbers
1,...,12
Prepending a zero to one-digit month numbers should be allowed e.g. 07
Matt...
-
Regular expression to match month number 1,...,12 (including e.g. 04,05)
How does a regular expression look like which should match exactly one of the
twelve possible month numbers
1,...,12
Prepending a zero to one-digit month numbers should be allowed e.g. 07
Matt
-
Re: Regular expression to match month number 1,...,12 (including e.g. 04,05)
Matt Benson wrote:
First, DO NOT CROSS-POST as you are doing. Choose at most two newsgroups.
> How does a regular expression look like which should match exactly one of
> the twelve possible month numbers
> 1,...,12
> Prepending a zero to one-digit month numbers should be allowed e.g. 07
Simple, but you need to say which language/utility/command you plan to
process the expression. The below won't find the single-digit versions, but
it will work for the double-digit forms:
(01|02|03|04|05|06|07|08|09|10|11|12)
Unambiguously and uniquely finding all the delimited cases is slightly more
complex.
--
Paul Lutus
http://www.arachnoid.com
-
Re: Regular expression to match month number 1,...,12 (including e.g. 04,05)
mbens@hotmail.com (Matt Benson) wrote in message news:...
> How does a regular expression look like which should match exactly one of the
> twelve possible month numbers
> 1,...,12
> Prepending a zero to one-digit month numbers should be allowed e.g. 07
>
> Matt
Maybe what you want is:
/^(0?[1-9]|1[0-2])$/
Regards
--
-Andrés Monroy-Hernández
-
Re: Regular expression to match month number 1,...,12 (including e.g. 04,05)
Paul Lutus wrote:
> Matt Benson wrote:
>
> First, DO NOT CROSS-POST as you are doing. Choose at most two
> newsgroups.
Oh come off it, he posted to groups that can be considered relevant to
this topic. RegEx, in the general sense, can be difficult to fully fit
into just one category. It's a part of sed, egrep, Perl, among many
other languages and tools. I'm sorry, but this is such a case when the
crossposting seems merited.
And come to think of it, that's the whole point of cross posting, to be
able to reach as many people for a given relevant topic without posting
multiple copies for each group (multi-posting), is it not?
>> How does a regular expression look like which should match exactly
>> one of the twelve possible month numbers
>> 1,...,12
>> Prepending a zero to one-digit month numbers should be allowed e.g.
>> 07
>
> Simple, but you need to say which language/utility/command you plan to
> process the expression. The below won't find the single-digit
> versions, but it will work for the double-digit forms:
>
> (01|02|03|04|05|06|07|08|09|10|11|12)
Why not (1[0-2]|0?[1-9]) ? Takes care of leading 0's too :-) Should
work with most tools, like Perl, sed, egrep, and the likes.
-
Re: Regular expression to match month number 1,...,12 (including e.g. 04,05)
Andres Monroy-Hernandez wrote:
> mbens@hotmail.com (Matt Benson) wrote in message
> news:...
>> How does a regular expression look like which should match exactly
>> one of the twelve possible month numbers
>> 1,...,12
>> Prepending a zero to one-digit month numbers should be allowed e.g.
>> 07
>>
>> Matt
>
> Maybe what you want is:
> /^(0?[1-9]|1[0-2])$/
Bah, shame your post didn't come down the feed before I posted. Yours is
basically the same, but I admit a bit better, but only if if the number
is the only thing on the line.
Perhaps something like:
/[^0-9]*(0?[1-9]|1[0-2])[^0-9]*/
Of if your RegEx engine supports \D (non-numeric) you can write it as:
/\D*(0?[1-9]|1[0-2])\D*/
That way it can be caught not just when it's in a line by itself :-)
-
Re: Regular expression to match month number 1,...,12 (including e.g. 04,05)
187 wrote:
> Paul Lutus wrote:
>> Matt Benson wrote:
>>
>> First, DO NOT CROSS-POST as you are doing. Choose at most two
>> newsgroups.
>
> Oh come off it, he posted to groups that can be considered relevant to
> this topic.
Read any beginner's guide to Usenet, then come back and retract.
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
Quote:
"It is considered highly inappropriate to broadcast your message to a wide
selection of newsgroups merely to have more people read it. Note also that
many people automatically ignore articles posted to more than two or three
groups."
http://www.usenet.com/articles/cross_posting.htm
Quote:
"You should cross-post only when it is really needed, and usually not to
more than three groups."
And so forth, through hundreds of such authoritative guides.
> RegEx, in the general sense, can be difficult to fully fit
> into just one category. It's a part of sed, egrep, Perl, among many
> other languages and tools. I'm sorry, but this is such a case when the
> crossposting seems merited.
No, first because such a wide cross-post is always unacceptable, and because
the OP must have some preliminary target environment in mind. That
environment has some specific traits.
>
> And come to think of it, that's the whole point of cross posting, to be
> able to reach as many people for a given relevant topic without posting
> multiple copies for each group (multi-posting), is it not?
Cross-posting to more than a few groups is unacceptable. See above.
>
>>> How does a regular expression look like which should match exactly
>>> one of the twelve possible month numbers
>>> 1,...,12
>>> Prepending a zero to one-digit month numbers should be allowed e.g.
>>> 07
>>
>> Simple, but you need to say which language/utility/command you plan to
>> process the expression. The below won't find the single-digit
>> versions, but it will work for the double-digit forms:
>>
>> (01|02|03|04|05|06|07|08|09|10|11|12)
>
> Why not (1[0-2]|0?[1-9]) ? Takes care of leading 0's too :-) Should
> work with most tools, like Perl, sed, egrep, and the likes.
Yes, my example is pretty bad, but since the OP did not say which engine he
is going to use, I didn't try to tune it for a specific environment. There
really are a lot of types of regex, of widely varying vintages. He needed
to say which regex engine he is planning to use, instead of crossposting.
--
Paul Lutus
http://www.arachnoid.com