Skip to content

Commit fca2dfa

Browse files
committed
Progress on more patterns in the library, link to test on RegexPlanet w/GET
1 parent 798fe81 commit fca2dfa

File tree

7 files changed

+201
-26
lines changed

7 files changed

+201
-26
lines changed

app/components/Patterns.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export type PatternEntry = {
1414
};
1515

1616
export type PatternEntryVariation = {
17-
title: string;
18-
pattern: string;
19-
replacement?: string;
2017
description?: string;
18+
engine?: string;
19+
inputs?: string[];
20+
options?: string[];
21+
regex: string;
22+
replacement?: string;
23+
title: string;
2124
};
2225

2326
const cache: Map<string, PatternEntry> = new Map();
@@ -39,7 +42,7 @@ async function initialize() {
3942
parsed.fullPath = fullPath;
4043

4144
cache.set(parsed.handle, parsed);
42-
//LATER: validate w/JSON schema
45+
//LATER: validate w/JSON schemaxx
4346
all.push(parsed);
4447
}
4548
}

app/routes/patterns.$entry._index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ function PatternEntryVariationView(variation: PatternEntryVariation) {
6464
<tr>
6565
<td>{variation.title}</td>
6666
<td>
67-
<code>{variation.pattern}</code>
67+
<code>{variation.regex}</code>
6868
</td>
6969
<td>
7070
<button
7171
className="btn btn-sm btn-outline-secondary ms-2 px-1 pt-0 pb-1"
72-
onClick={() => copyToClipboard(variation.pattern)}
72+
onClick={() => copyToClipboard(variation.regex)}
7373
><PiClipboardBold title="copy to clipboard" /></button>
74-
<form action="https://www.regexplanet.com/advanced/java/index.html" className="d-inline" method="post" target="_blank">
75-
<input type="hidden" name="regex" value={variation.pattern} />
76-
<input type="hidden" name="replacement" value={variation.replacement} />
74+
<form action="https://www.regexplanet.com/advanced/java/index.html" className="d-inline" method="get" target="_blank">
75+
<input type="hidden" name="regex" value={variation.regex} />
76+
{ variation.replacement ? <input type="hidden" name="replacement" value={variation.replacement} /> : null }
77+
{ variation.options ? variation.options.map((option, index) => <input key={`option_${index}`} type="hidden" name="options" value={option} />) : null }
78+
{ variation.inputs ? variation.inputs.map((input, index) => <input key={`input_${index}`} type="hidden" name="input" value={input} />) : null }
7779
<button className="btn btn-sm btn-outline-secondary ms-2 px-1 pt-0 pb-1" ><PiPlayBold title="Test" /></button>
7880
</form>
7981
</td>

patterns/ap-dates.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
featured: false
2+
handle: ap-dates
3+
title: Associated Press Date Format
4+
tags:
5+
- date
6+
variations:
7+
- title: "AP Date (standalone)"
8+
regex: '^(January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$'
9+
inputs:
10+
- "January 1, 2020"
11+
- "February 29, 2020"
12+
- "March 15, 2020"
13+
- "April 30, 2020"
14+
- "May 1, 2020"
15+
- "June 15, 2020"
16+
- "July 31, 2020"
17+
- "August 1, 2020"
18+
- "September 15, 2020"
19+
- "October 31, 2020"
20+
- "November 1, 2020"
21+
- "December 15, 2020"
22+
- title: "AP Date (inline)"
23+
regex: '\b(January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}\b'
24+
inputs:
25+
- "My birthday is on January 1, 2020."
26+
- "I was born on February 29, 2020."
27+
- "The Ides of March is on March 15, 2020."
28+
- "April 30, 2020 is the last day of the month."
29+
- "May 1, 2020 is the first day of the month."
30+
- "June 15, 2020 is halfway through the month."
31+
- "July 31, 2020 is the last day of the month."
32+
- "August 1, 2020 is the first day of the month."
33+
- "September 15, 2020 is halfway through the month."
34+
- "October 31, 2020 is Halloween."
35+
- "November 1, 2020 is the day after Halloween."
36+
- "December 15, 2020 is halfway through the month."

patterns/color.yaml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ tags:
77
- html
88
variations:
99
- title: "Hex (standalone)"
10-
pattern: "^(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))$"
11-
tests:
12-
- text: "#f00"
13-
- text: "#ff0000"
14-
- text: "#0f0"
15-
- text: "#00ff00"
16-
- text: "#00f"
17-
- text: "#0000ff"
18-
- text: "#000"
19-
- text: "#000000"
20-
- text: "#fff"
21-
- text: "#ffffff"
10+
regex: "^(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))$"
11+
inputs:
12+
- "#f00"
13+
- "#ff0000"
14+
- "#0f0"
15+
- "#00ff00"
16+
- "#00f"
17+
- "#0000ff"
18+
- "#000"
19+
- "#000000"
20+
- "#fff"
21+
- "#ffffff"
2222
- title: "Hex (inline)"
23-
pattern: "\\b(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))\\b"
23+
regex: "\\b(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))\\b"
24+
inputs:
25+
- "My favorite color is #f00!"

patterns/iso8601-date.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
featured: true
2+
handle: iso8601-date
3+
title: ISO 8601 Date Format
4+
tags:
5+
- date
6+
todo: "Handle millis, missing separators, etc."
7+
variations:
8+
- title: "ISO 8601 Complete"
9+
description: "from the [Intervals Blog](https://www.myintervals.com/blog/iso-8601-date-validation/)"
10+
regex: '^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$'
11+
inputs:
12+
- "2009-12T12:34"
13+
- "2009"
14+
- "2009-05-19"
15+
- "2009-05-19"
16+
- "20090519"
17+
- "2009123"
18+
- "2009-05"
19+
- "2009-123"
20+
- "2009-222"
21+
- "2009-001"
22+
- "2009-W01-1"
23+
- "2009-W51-1"
24+
- "2009-W511"
25+
- "2009-W33"
26+
- "2009W511"
27+
- "2009-05-19"
28+
- "2009-05-19 00:00"
29+
- "2009-05-19 14"
30+
- "2009-05-19 14:31"
31+
- "2009-05-19 14:39:22"
32+
- "2009-05-19T14:39Z"
33+
- "2009-W21-2"
34+
- "2009-W21-2T01:22"
35+
- "2009-139"
36+
- "2009-05-19 14:39:22-06:00"
37+
- "2009-05-19 14:39:22+0600"
38+
- "2009-05-19 14:39:22-01"
39+
- "20090621T0545Z"
40+
- "2007-04-06T00:00"
41+
- "2007-04-05T24:00"
42+
- "2010-02-18T16:23:48.5"
43+
- "2010-02-18T16:23:48,444"
44+
- "2010-02-18T16:23:48,3-06:00"
45+
- "2010-02-18T16:23.4"
46+
- "2010-02-18T16:23,25"
47+
- "2010-02-18T16:23.33+0600"
48+
- "2010-02-18T16.23334444"
49+
- "2010-02-18T16,2283"
50+
- "2009-05-19 143922.500"
51+
- "2009-05-19 1439,55"
52+
- title: "ISO 8601 Date (standalone)"
53+
regex: '^\d{4}-\d{2}-\d{2}$'
54+
inputs:
55+
- "2020-01-01"
56+
- "2020-02-29"
57+
- "2020-03-15"
58+
- "2020-04-30"
59+
- "2020-05-01"
60+
- "2020-06-15"
61+
- "2020-07-31"
62+
- "2020-08-01"
63+
- "2020-09-15"
64+
- "2020-10-31"
65+
- "2020-11-01"
66+
- "2020-12-15"
67+
- title: "ISO 8601 Date (inline)"
68+
regex: '\b\d{4}-\d{2}-\d{2}\b'
69+
inputs:
70+
- "My birthday is on 2020-01-01."
71+
- "I was born on 1970-01-01."
72+
- "The Ides of March is on 2020-03-15."
73+
- "2020-04-30 is the last day of the month."
74+
- "2020-05-01 is the first day of the month."
75+
- "2020-06-15 is halfway through the month."
76+
- "2020-07-31 is the last day of the month."
77+
- "2020-08-01 is the first day of the month."
78+
- "2020-09-15 is halfway through the month."
79+
- "2020-10-31 is Halloween."
80+
- "2020-11-01 is the day after Halloween."
81+
- "2020-12-15 is halfway through the month."
82+
- title: "ISO 8601 date+time (standalone)"
83+
regex: '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$'
84+
inputs:
85+
- "2020-01-01T00:00:00"
86+
- "2020-02-29T12:34:56"
87+
- "2020-03-15T23:59:59"
88+
- "2020-04-30T01:23:45"
89+
- "2020-05-01T12:34:56"
90+
- "2020-06-15T23:59:59"
91+
- "2020-07-31T01:23:45"
92+
- "2020-08-01T12:34:56"
93+
- "2020-09-15T23:59:59"
94+
- "2020-10-31T01:23:45"
95+
- "2020-11-01T12:34:56"
96+
- "2020-12-15T23:59:59"
97+
- title: "ISO 8601 simple date+time (inline)"
98+
regex: '\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\b'
99+
inputs:
100+
- "My birthday is on 2020-01-01T00:00:00."
101+
- "I was born on 1970-01-01T00:00:00."
102+
- "The Ides of March is on 2020-03-15T23:59:59."
103+
- "2020-04-30T01:23:45 is the last day of the month."
104+
- "2020-05-01T12:34:56 is the first day of the month."
105+
- "2020-06-15T23:59:59 is halfway through the month."
106+
- "2020-07-31T01:23:45 is the last day of the month."
107+
- "2020-08-01T12:34:56 is the first day of the month."
108+
- "2020-09-15T23:59:59 is halfway through the month."
109+
- "2020-10-31T01:23:45 is Halloween."
110+
- "2020-11-01T12:34:56 is the day after Halloween."
111+
- "2020-12-15T23:59:59 is halfway through the month."

patterns/roman-numeral.yaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
featured: true
22
handle: roman-numeral
3+
tags:
4+
- numbers
35
title: Roman Numerals
6+
inputs: &common_inputs
7+
- "I"
8+
- "i"
9+
- "V"
10+
- "v"
11+
- "VI"
12+
- "IV"
13+
- "IX"
14+
- "X"
15+
- "XI"
16+
- "XIV"
17+
- "XIX"
18+
- "XX"
419
variations:
520
- title: "Roman Numerals (standalone)"
6-
pattern: "^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
21+
regex: "^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
22+
inputs: *common_inputs
723
- title: "Roman Numerals (inline)"
8-
pattern: "\\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\\b"
24+
regex: "\\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\\b"
25+
inputs: *common_inputs

patterns/zip-code.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ tags:
1111
- us
1212
variations:
1313
- title: "US Zip Code (standalone)"
14-
pattern: "^((\\d{5})(-\\d{4})?)$"
14+
regex: '^((\d{5})(-\d{4})?)$'
15+
replacement: 'zip code is "\1"'
16+
inputs:
17+
- "12345"
18+
- "12345-6789"
1519
- title: "US Zip Code (inline)"
16-
pattern: "\\b((\\d{5})(-\\d{4})?)\\b"
20+
regex: '\b((\d{5})(-\d{4})?)\b'

0 commit comments

Comments
 (0)