Hi,
Can anyone help out with a regex for time?
I would like the regex to accept:
HH:MM AM
HH:MM PM
Optional space, optional 1st H, case doesn't matter. Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! 9 1514
Hi Ron,
Try this one:
(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?)See you,Roberto
Lopes"Ron" <ju*********@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl... Hi,
Can anyone help out with a regex for time?
I would like the regex to accept:
HH:MM AM HH:MM PM
Optional space, optional 1st H, case doesn't matter. Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Thanks for the quick reply Roberto.
Am I supposed to include the whole string, starting w/:
"(?<Time>^........[ap],?)"
When I do include it all, the browser gets a "Syntax Error in Regular
Expression" and it doesn't work.
When I remove the "(?<Time>" from the beg. and one ) from the end, the
expression accepts 1:00 w/o the PM, which is not ok. Am am I doing
something wrong? Thanks again.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi Ron,
It's pretty strange, because I tryed befor send you. Try do it like this:
Dim regxInteger As New
System.Text.RegularExpressions.Regex("(?<Time>^(?: 0?[1-9]:[0-5]|1(?=[012])\d
:[0-5])\d(?:[ap]m)?)")
MessageBox.Show(regxInteger.IsMatch("12:0aAM").ToS tring)
I hope it works.
See you,
Roberto Lopes
"Roberto Lopes" <ro************@yahoo.ca> wrote in message
news:um**************@TK2MSFTNGP14.phx.gbl... Hi Ron,
Try this one:
(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?)See you,Roberto Lopes"Ron" <ju*********@hotmail.com> wrote in message news:OG**************@TK2MSFTNGP15.phx.gbl... Hi,
Can anyone help out with a regex for time?
I would like the regex to accept:
HH:MM AM HH:MM PM
Optional space, optional 1st H, case doesn't matter. Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Ron,
Realize that the example I sent you will return false, because the time is
wrong, ok?
Try testing a valid time like this:
Dim regxInteger As New
System.Text.RegularExpressions.Regex("(?<Time>^(?: 0?[1-9]:[0-5]|1(?=[012])\d
:[0-5])\d(?:[ap]m)?)")
MessageBox.Show(regxInteger.IsMatch("12:00 AM").ToString)
Ok?
Thanks,
Roberto Lopes
"Ron" <ju*********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl... Thanks for the quick reply Roberto.
Am I supposed to include the whole string, starting w/:
"(?<Time>^........[ap],?)"
When I do include it all, the browser gets a "Syntax Error in Regular Expression" and it doesn't work.
When I remove the "(?<Time>" from the beg. and one ) from the end, the expression accepts 1:00 w/o the PM, which is not ok. Am am I doing something wrong? Thanks again.
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi again,
I got these examples to work, however the expression accepts a time w/o
the AM or PM. AM/PM must be included, meaning '1:00' should return
false.
I also keep getting the bad syntax error when I tab out of the validated
txtbox.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi Ron,
I didn't know it was mandadory. Try this one:
Dim regxInteger As New
System.Text.RegularExpressions.Regex("(^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])
\d( )?(AM|am|aM|Am|PM|pm|pM|Pm))$")
Write back telling if it worked fine, ok?
See you.
Roberto Lopes
"Ron" <ju*********@hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl... Hi again,
I got these examples to work, however the expression accepts a time w/o the AM or PM. AM/PM must be included, meaning '1:00' should return false.
I also keep getting the bad syntax error when I tab out of the validated txtbox. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
That seems to be working great!!!
I noticed you took out '<time>'. Is that what was causing the syntax
errors (which I no longer get)?
Also, any suggestions on where I can get a listing of the symbols and
how they are used? Thank you very much.
--Ron
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi Ron,
That sounds good it worked fine.
You can go to http://www.regexlib.com/
Great resource to RegEx patterns.
See you,
Roberto Lopes
"Ron" <ju*********@hotmail.com> wrote in message
news:uP*************@TK2MSFTNGP10.phx.gbl... That seems to be working great!!!
I noticed you took out '<time>'. Is that what was causing the syntax errors (which I no longer get)?
Also, any suggestions on where I can get a listing of the symbols and how they are used? Thank you very much.
--Ron
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Conner |
last post by:
Is there a way to write a faster function ?
public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^+$" ))
{
return true;
}
else return false;
}
|
by: rjb |
last post by:
Hi there
I have a text file which looks like the one below.
I'm trying to write a program which will go through each of those lines
(for each section separated by an empty line) and give me:
...
|
by: rjb |
last post by:
Hi!
Could somebody have a look and help me to optimize the code below.
It may look like very bad way of coding, but this stuff is very, very new
for me.
I've included just few lines.
Regex...
|
by: John Grandy |
last post by:
Is it advisable to compile a Regex for a massively scalable ASP.NET
web-application ?
How exactly does this work ?
Do you create a separate class library and expose the Regex.Replace() as a...
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
...
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: ohmmega |
last post by:
hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set...
|
by: Karch |
last post by:
I have these two methods that are chewing up a ton of CPU time in my
application. Does anyone have any suggestions on how to optimize them or
rewrite them without Regex? The most time-consuming...
|
by: Danny Ni |
last post by:
Hi,
The following code snippet is causing CPU to max out on my local machine and
production servers. It looks fine on Expresso though.
Regex rgxVideo = new...
|
by: |
last post by:
Hi all,
Sorry for the lengthy post but as I learned I should post
concise-and-complete code.
So the code belows shows that the execution of ValidateAddress consumes a
lot of time. In the test...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |