473,788 Members | 2,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex - Time

Ron
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!
Nov 18 '05 #1
9 1528
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*********@ho tmail.com> wrote in message
news:OG******** ******@TK2MSFTN GP15.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!

Nov 18 '05 #2
Ron
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!
Nov 18 '05 #3
Hi Ron,

It's pretty strange, because I tryed befor send you. Try do it like this:

Dim regxInteger As New
System.Text.Reg ularExpressions .Regex("(?<Time >^(?:0?[1-9]:[0-5]|1(?=[012])\d
:[0-5])\d(?:[ap]m)?)")

MessageBox.Show (regxInteger.Is Match("12:0aAM" ).ToString)

I hope it works.

See you,

Roberto Lopes

"Roberto Lopes" <ro************ @yahoo.ca> wrote in message
news:um******** ******@TK2MSFTN GP14.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*********@ho tmail.com> wrote in message
news:OG******** ******@TK2MSFTN GP15.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!


Nov 18 '05 #4
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.Reg ularExpressions .Regex("(?<Time >^(?:0?[1-9]:[0-5]|1(?=[012])\d
:[0-5])\d(?:[ap]m)?)")

MessageBox.Show (regxInteger.Is Match("12:00 AM").ToString )

Ok?

Thanks,

Roberto Lopes

"Ron" <ju*********@ho tmail.com> wrote in message
news:uf******** ******@TK2MSFTN GP11.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!

Nov 18 '05 #5
Ron
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!
Nov 18 '05 #6
Hi Ron,

I didn't know it was mandadory. Try this one:
Dim regxInteger As New
System.Text.Reg ularExpressions .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*********@ho tmail.com> wrote in message
news:ud******** ******@TK2MSFTN GP10.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!

Nov 18 '05 #7
Ron
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!
Nov 18 '05 #8
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*********@ho tmail.com> wrote in message
news:uP******** *****@TK2MSFTNG P10.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!

Nov 18 '05 #9
Ron wrote:
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.


A great place to find pre-made regular expressions is www.RegExLib.com.
Here are the results when searching on the keyword "time":
http://regexlib.com/Search.aspx?k=time

--

Scott Mitchell
mi******@4guysf romrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla. com!
Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4592
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; }
2
2685
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: Day, Month, HH, MM, SS, Year, User-Name, Acct-Multi-Session-Id, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Input-Octets, Acct-Output-Octets.
8
1863
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 regxUserName = new Regex(@"(?<=User-Name = )\""(+)\""", RegexOptions.None);
2
4285
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 method ..... ..... or can you just use the syntax :
17
3980
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 http://forta.com/books/0672325667/
15
50262
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
14
2262
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 zero or more char's. (zero or one was easy). thank's rené
0
1735
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 operation by a long-shot is the regex.Replace. Basically the only purpose of it is to remove spaces between opening/closing tags and the element name. Surely there is a better way. private string FixupJavascript(string htmlCode) { string result...
4
2303
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 Regex(@"<embed(\s++\s*=\s*(""*""|'*'|*))*\s+src=\s*(""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+)(""|')?(\s++\s*=\s*(""*""|'*'|*))*\s*(/\s*>|>\s*</embed>)", RegexOptions.IgnoreCase); string strBody = "<embed name=\"VideoPlayer\" src=\"http://localhost/lv3/26757\" width=\"480\"...
6
2074
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 it is called a 100 times but in my real app it could be called 50000 or more times. So my question is if it is somehow possible to speed this up and if so how
0
10373
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.