Date/Time
Weekday Name Regex
Schedules, opening hours and chat messages often mention weekdays by name or by short forms such as Mon, Tue, Tues, Thu and Thurs. This pattern finds any of them as a whole word, case-insensitively, by combining a stem with an optional day suffix. Word boundaries stop it from matching inside words like Monster, Sunflower or Friend. It is useful for parsing opening-hours text, extracting meeting days from emails and building natural language scheduling features. The honest limit is that the structure also allows a few unusual combinations, such as Thurday, which are not standard spellings.
Pattern (JavaScript)
/\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b/iMatches a word boundary, then (the text "Mon" OR the text "Tue", then the character "s", optionally (zero or one time) OR the text "Wed", then (the text "nes"), optionally (zero or one time) OR the text "Thu", then (the character "r", then the character "s", optionally (zero or one time)), optionally (zero or one time) OR the text "Fri" OR the text "Sat", then (the text "ur"), optionally (zero or one time) OR the text "Sun"), then (the text "day"), optionally (zero or one time), then a word boundary.
Examples
Matches
- ✓ Monday
- ✓ see you Thu
- ✓ SATURDAY
Does not match
- ✗ Sunflower
- ✗ Monster
- ✗ Friend
Try it
3 matches (JavaScript engine)
Monday see you Thu SATURDAY Sunflower Monster Friend
Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b/gi;
const text = "Monday";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b', re.I)
text = 'Monday'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b/i';
$text = 'Monday';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("\\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\\b", Pattern.CASE_INSENSITIVE);
String text = "Monday";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b`)
text := "Monday"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b", RegexOptions.IgnoreCase);
var text = "Monday";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"(?i)\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b").unwrap();
let text = "Monday";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /\b(?:Mon|Tues?|Wed(?:nes)?|Thu(?:rs?)?|Fri|Sat(?:ur)?|Sun)(?:day)?\b/i
text = 'Monday'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why does the pattern use stems plus an optional day?
- Every weekday ends in day, so the stems Mon, Tues, Wednes, Thurs, Fri, Satur and Sun plus an optional day cover both full and short forms compactly.
- How do I match ranges like Mon-Fri?
- Combine the pattern with itself: put a group of it, then a dash or the word to, then the group again. Capturing both sides lets you expand the range in code.
- Can I map the result to a day number?
- Yes, take the first three letters of the match in lowercase and look them up in a map from mon to 1 through sun to 7, or whichever numbering your system uses.
Related patterns
- 24-Hour Time (HH:MM)^([01][0-9]|2[0-3]):([0-5][0-9])$
- Date with Month Name^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$
- Month Name\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b
- 12-Hour Time with AM/PM^(0?[1-9]|1[0-2]):[0-5][0-9] ?[AaPp][Mm]$