Regular Expression to Find Day of Week

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mwaw
Forum Newbie
Posts: 19
Joined: Sun Aug 11, 2002 12:31 am
Location: California

Regular Expression to Find Day of Week

Post by mwaw »

I want to search text strings to see if they start with a day of the week (Monday or Tuesday or Wednesday, etc.)

Among other things, I've tried ^(Monday)*(Tuesday)*(Wednesday)...... but the problem is how to end it. Or, perhaps I just need a different approach.

Would it actually be a better idea to put the days of the week in an array and loop throught the array to see if any of the elements match the first word of the string?

Thanks!

Mike Wilkinson
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Regular Expression

Post by Takuma »

^(Monday|Tuesday|Wednesday|Thurday|Friday|Saturday|Sunday)$

I think that's it... If you want to learn more about Regular Expression check this out:-
http://www.phpbuilder.com/columns/dario19990616.php3
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

That will see if the string is a day of the week to see if it starts with a day of the week knock of the $ and use eregi so it is case insensitive.
mwaw
Forum Newbie
Posts: 19
Joined: Sun Aug 11, 2002 12:31 am
Location: California

Thanks for the tips!

Post by mwaw »

Thanks for the tips.

For some reason my reference did not have any info on the OR function, so I didn't know that it was available.

Mike Wilkinson
Post Reply