├── README.md ├── assets ├── main.js ├── style.css └── challenge.js ├── challenge13.html ├── challenge12.html ├── challenge3.html ├── challenge11.html ├── challenge4.html ├── challenge1.html ├── challenge5.html ├── challenge8.html ├── challenge9.html ├── challenge17.html ├── challenge2.html ├── challenge6.html ├── challenge7.html ├── challenge10.html ├── challenge18.html ├── index.html ├── challenge14.html ├── challenge15.html ├── challenge20.html ├── challenge16.html └── challenge19.html /README.md: -------------------------------------------------------------------------------- 1 | **Repo for Regex Tuesday challenges.** 2 | 3 | http://callumacrae.github.com/regex-tuesday/ 4 | 5 | Regex Tuesday Challenges by [Callum Macrae](http://lynx.io/). Follow him [on Twitter](http://twitter.com/callumacrae) for announcements when new challenges are posted, and of course - tell your friends about Regex Tuesday! 6 | -------------------------------------------------------------------------------- /assets/main.js: -------------------------------------------------------------------------------- 1 | var dates = document.getElementsByTagName('date'), 2 | date, diff, i; 3 | 4 | // Prettify the dates 5 | for (i = dates.length - 1; i >= 0; i--) { 6 | date = dates[i].textContent.split('/'); 7 | date = new Date(date[2], date[1] - 1, date[0]); 8 | 9 | diff = Math.floor((Date.now() - date.getTime()) / 86400000); 10 | 11 | if (diff === 0) { 12 | dates[i].textContent = 'Today'; 13 | } else if (diff === 1) { 14 | dates[i].textContent = 'Yesterday'; 15 | } else if (diff <= 7) { 16 | dates[i].textContent = diff + ' days ago'; 17 | } else if (diff < 62) { 18 | dates[i].textContent = Math.ceil(diff / 7) + ' weeks ago'; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /assets/style.css: -------------------------------------------------------------------------------- 1 | head, body { 2 | font-family: "Source Sans Pro"; 3 | font-size: 14px; 4 | color: #202020; 5 | } 6 | 7 | header { 8 | margin: 30px auto; 9 | text-align: center; 10 | } 11 | 12 | header h1 { 13 | margin: 0 0 30px; 14 | 15 | font-weight: 200; 16 | font-size: 50px; 17 | } 18 | 19 | #social { 20 | margin-top: 20px; 21 | height: 26px; 22 | } 23 | 24 | a { 25 | color: #457AA8; 26 | text-decoration: none; 27 | } 28 | 29 | a:hover { 30 | text-decoration: underline; 31 | } 32 | 33 | a:active { 34 | opacity: 0.7; 35 | } 36 | 37 | nav a, .button { 38 | padding: 4px 12px; 39 | margin: 0 5px; 40 | } 41 | 42 | nav a, .challenge, .button { 43 | font-size: 14px; 44 | text-decoration: none; 45 | color: #202020; 46 | background: #F7F7F7; 47 | border: 1px solid #EDEDED; 48 | border-radius: 3px; 49 | box-shadow: inset 0 1px 0 0 #fff; 50 | outline: 0; 51 | } 52 | 53 | nav a:hover, nav a:focus, 54 | .challenge:hover, .challenge:focus, 55 | .button:hover, .button:focus { 56 | border-color: #457AA8; 57 | text-decoration: none; 58 | } 59 | 60 | nav a:active, .challenge:active, .button:active { 61 | opacity: 0.7; 62 | } 63 | 64 | section { 65 | width: 600px; 66 | margin: 0 auto; 67 | } 68 | 69 | section p { 70 | text-align: justify; 71 | } 72 | 73 | section h2 { 74 | margin: 30px 0 20px; 75 | 76 | font-weight: normal; 77 | font-size: 22px; 78 | } 79 | 80 | section h3 { 81 | margin: 20px 10px 10px; 82 | 83 | font-weight: normal; 84 | font-size: 20px; 85 | } 86 | 87 | .challenges { 88 | list-style-type: none; 89 | padding: 0; 90 | } 91 | 92 | .challenge { 93 | display: block; 94 | margin-bottom: 20px; 95 | } 96 | 97 | .challenge date { 98 | display: inline-block; 99 | padding: 10px; 100 | width: 90px; 101 | margin-right: 10px; 102 | 103 | text-align: center; 104 | color: #787878; 105 | border-right: 1px solid #EDEDED; 106 | } 107 | 108 | input:not([type="checkbox"]), dt, dd, textarea, #congratulations { 109 | padding: 10px; 110 | margin: 0 8px; 111 | width: 260px; 112 | 113 | outline: none; 114 | border-radius: 3px; 115 | border: 1px solid #CFCFCF; 116 | font-family: monospace; 117 | } 118 | 119 | .single-input input, textarea { 120 | width: 560px; 121 | } 122 | 123 | input:focus, textarea:focus { 124 | border-color: #457AA8; 125 | } 126 | 127 | input.invalid, textarea.invalid { 128 | border-color: #D14B4B; 129 | } 130 | 131 | .hide_passing .passed { 132 | display: none; 133 | } 134 | 135 | h3 { 136 | margin-left: 8px; 137 | } 138 | 139 | h3 #hide_passing { 140 | font-size: 10pt; 141 | float: right; 142 | } 143 | 144 | dt, dd { 145 | margin-bottom: 20px; 146 | white-space: pre-wrap; 147 | } 148 | 149 | dt { 150 | clear: both; 151 | float: left; 152 | } 153 | 154 | dt:before { 155 | display: inline-block; 156 | height: 0px; 157 | float: right; 158 | content: "»"; 159 | margin-right: -26px; 160 | margin-top: -4px; 161 | font-size: 19px; 162 | } 163 | 164 | dt.passed, dt.passed + dd { 165 | border-color: #BAED9D; 166 | background: #D0F7BA; 167 | } 168 | 169 | dt.failed, dt.failed + dd, input.invalid { 170 | border-color: #F2BEA7; 171 | background: #FFDAC9; 172 | } 173 | 174 | dd { 175 | margin-left: 309px; 176 | } 177 | 178 | dd + dd { 179 | border-style: dashed; 180 | display: none; 181 | } 182 | 183 | dd.showfail + dd { 184 | display: block; 185 | } 186 | 187 | footer { 188 | margin: 50px 0 30px; 189 | text-align: center; 190 | color: #A3A3A3; 191 | } 192 | 193 | #congratulations { 194 | width: 560px; 195 | display: none; 196 | } 197 | 198 | .hide_passing.all_passing #congratulations { 199 | display: block; 200 | } 201 | 202 | -------------------------------------------------------------------------------- /assets/challenge.js: -------------------------------------------------------------------------------- 1 | var find = document.getElementById('find'), 2 | hidePassing = document.querySelectorAll('#hide_passing input')[0], 3 | replace = document.getElementById('replace'), 4 | passedCount = document.getElementById('passed-count'), 5 | testElements = document.getElementById('tests').getElementsByTagName('dt'), 6 | permalink = document.getElementById('permalink'), 7 | cases = [], 8 | element, i, urlParts; 9 | 10 | // Loop over the list of test cases and put them in an array 11 | for (i = 0; i < testElements.length; i++) { 12 | element = testElements[i]; 13 | cases[i] = { 14 | input: htmlToText(element.innerHTML), 15 | output: htmlToText(element.nextSibling.innerHTML) 16 | }; 17 | 18 | // Add the "it should've been X" element to each test case 19 | element.parentNode.insertBefore(document.createElement('dd'), 20 | element.nextSibling.nextSibling); 21 | }; 22 | 23 | // For validating and live-testing of the regex 24 | find.addEventListener('keyup', function(e){ 25 | validateRegex(false); 26 | }); 27 | find.addEventListener('blur', function(e){ 28 | validateRegex(true); 29 | }); 30 | 31 | if (replace){ 32 | replace.addEventListener('keyup', function(e){ 33 | validateRegex(true); 34 | }); 35 | } 36 | 37 | // Allow the URL to contain regex and replace values 38 | urlParts = location.search.replace('?', '').split(/[\&\=]/); 39 | for (i = 0; i < urlParts.length; i += 2){ 40 | if (urlParts[i] == 'find' && find) { 41 | find.value = decodeURIComponent(urlParts[i + 1]); 42 | } 43 | if (urlParts[i] == 'replace' && replace) { 44 | replace.value = decodeURIComponent(urlParts[i + 1]); 45 | } 46 | } 47 | 48 | if (find.value) { 49 | validateRegex(true); 50 | } 51 | 52 | // Handle "Hide passing tests" 53 | hidePassing.addEventListener('change', function () { 54 | document.body.classList.toggle('hide_passing'); 55 | window.localStorage.hidePassing = this.checked; 56 | }); 57 | 58 | if (window.localStorage.hidePassing === 'true') { 59 | document.body.classList.add('hide_passing'); 60 | hidePassing.checked = true; 61 | } 62 | 63 | function validateRegex(warnUser) { 64 | var regex = find.value, 65 | url = location.origin + location.pathname, 66 | passes = 0, fails = 0, 67 | element, i, newClass, output, test; 68 | 69 | url += '?find=' + encodeURIComponent(find.value); 70 | if (replace) { 71 | url += '&replace=' + encodeURIComponent(replace.value); 72 | } 73 | permalink.setAttribute('href', url); 74 | 75 | if (regex === '') { 76 | find.className = ''; 77 | return false; 78 | } 79 | 80 | // Validating regex using regex... that's meta. 81 | if (regex = /^\/(.*)\/([a-z]*)$/.exec(regex)) { 82 | try { 83 | if (regex[2].indexOf('x') !== -1) { 84 | regex[1] = regex[1].replace(/([^\\]|^)\s/g, '$1'); 85 | regex[2] = regex[2].replace('x', ''); 86 | } 87 | 88 | regex = new RegExp(regex[1], regex[2]); 89 | } catch (error) { 90 | if (warnUser) { 91 | find.className = 'invalid'; 92 | } 93 | return false; 94 | } 95 | 96 | // Valid regex! 97 | find.className = ''; 98 | 99 | for (i = 0; i < cases.length; i++) { 100 | test = cases[i]; 101 | element = testElements[i]; 102 | 103 | if (replace) { 104 | output = test.input.replace(regex, replace.value); 105 | element.nextSibling.nextSibling.innerHTML = textToHtml(output); 106 | if (output === test.output) { 107 | newClass = 'passed'; 108 | passes++; 109 | } else { 110 | newClass = 'failed showfail'; 111 | fails++; 112 | } 113 | } else { 114 | if (regex.test(test.input) === (test.output === 'match')) { 115 | newClass = 'passed'; 116 | passes++; 117 | } else { 118 | newClass = 'failed'; 119 | } 120 | } 121 | 122 | element.nextSibling.className = element.className = newClass; 123 | } 124 | 125 | // Let the user know how many tests they passed 126 | passedCount.textContent = passes; 127 | 128 | if (fails === 0) { 129 | document.body.classList.add('all_passing'); 130 | } else { 131 | document.body.classList.remove('all_passing'); 132 | } 133 | 134 | return true; 135 | } else if (warnUser) { 136 | find.className = 'invalid'; 137 | } 138 | 139 | return false; 140 | } 141 | 142 | function htmlToText(html) { 143 | return html.replace(/\/g, '\n') 144 | .replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); 145 | } 146 | 147 | function textToHtml(text) { 148 | return text.replace(/&/g, '&').replace(/\/g, '>') 149 | .replace(/\n/g, '
'); 150 | } 151 | -------------------------------------------------------------------------------- /challenge13.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Thirteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Thirteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

Regex Tuesday Challenge #13 is to match strings which have a word repeated directly below the same word on the previous line (see the test cases if that isn't clear). The font is mono-spaced today, so the lines are all the same width. Be aware that the line wraps by itself if the last word is too long.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/8)

37 |
38 |
This sentence is pretty long and this sentence is also a test
match
39 |
40 |
This sentence is also long and this sentence is a test
match
41 |
42 |
This sentence shouldn't match
no match
43 |
This sentence also shouldn't match as this has no words below.
no match
44 |

45 |
Hello world, this exclamation of surprise has this by surprise
match
46 |
47 |
Hello world, this exclamation of surprise is this by surprise
no match
48 |
49 |
While there are no repeated words on the first line, these words repeat again on this line.
match
50 |

51 |
"No!", shouted the boy, crying. "No!"
match
52 |
53 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
54 |
55 | 56 | 59 | 60 | 61 | 62 | 63 | 72 | 79 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /challenge12.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Twelve 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Twelve

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

This weeks challenge is another slightly easier challenge. In it, you must fix the whitespace in a sentence or paragraph; before, there could be multiple spaces or tabs between two words. You must write a regex such that the final string has one space between words, and two spaces after full stops (hint; there will never be a tab following a full stop). New lines should be left alone.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 | 35 |

36 | 37 |

Test cases (0/12)

38 |
39 |
This is already a valid sentence.
This is already a valid sentence.
40 |
Extra spaces
Extra spaces
41 |
Multiple extra spaces
Multiple extra spaces
42 |
Tab here
Tab here
43 |
Multiple tabs here
Multiple tabs here
44 |
Tab and spaces
Tab and spaces
45 |
Multiple tabs
Multiple tabs
46 |
Mixed whitespace
Mixed whitespace
47 |
Sentence. Sentence.
Sentence. Sentence.
48 |
Sentence with words. Sentence.
Sentence with words. Sentence.
49 |
The quick brown fox. Jumped.
The quick brown fox. Jumped.
50 |
There are 1.2 apples
There are 1.2 apples
51 |
52 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
53 |
54 | 55 | 58 | 59 | 60 | 61 | 62 | 71 | 78 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /challenge3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Three 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Three

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

The third regex tuesday challenge is to match dates in YYYY/MM/DD HH:MM(:SS) format. YYYY should be a year between 1000 and 2012, and everything else should be a valid month, date, hour, minute and second. The seconds should be optional. Don't worry about leap years, and assume that all months have 30 days.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/19)

37 |
38 |
2012/09/18 12:10
match
39 |
2001/09/30 23:59:11
match
40 |
1995/12/01 12:12:12
match
41 |
1001/01/07 14:27
match
42 |
2010/10/20 10:10
match
43 |
2000/01/01 01:01:01
match
44 |
2007/07/22 22:34:59
match
45 |
2010/05/05 00:00:00
match
46 | 47 |
2012/9/18 23:40
no match
48 |
2013/09/09 09:09
no match
49 |
2012/00/01 01:49:59
no match
50 |
2012/13/25 22:17:00
no match
51 |
1994/11/00 12:12
no match
52 |
2012/12/4 12:12
no match
53 |
2009/11/11 24:00:00
no match
54 |
2012/06/24 13:60
no match
55 |
2002/10/10 14:59:60
no match
56 |
a2011/11/11 11:11:11
no match
57 |
2005/05/05 05:05:05d
no match
58 |
59 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
60 |
61 | 62 | 65 | 66 | 67 | 68 | 69 | 78 | 85 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /challenge11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Eleven 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Eleven

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

Let's play golf! This challenge is to match strings where the letters are in alphabetical order - for example, abcfjz would pass, but acb would not. Whitespace should be ignored - ab c d should pass. You have to try to get the regular expression as short as possible!

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/26)

37 |
38 |
abc
match
39 |
abcdefghijk
match
40 |
abdfkmnpstvxz
match
41 |
cxy
match
42 |
cdklstxy
match
43 |
bfrtw
match
44 |
a b c
match
45 |
acg jko pr
match
46 |
a z
match
47 |
v z
match
48 |
a b cdefg kl
match
49 |
uv xyz
match
50 |
ab de gh
match
51 |
x yz
match
52 |
abcdefghijklmnopqrstuvwxyz
match
53 | 54 |
abbc
no match
55 |
abcb
no match
56 |
a bcdjkrza
no match
57 |
qwerty
no match
58 |
zyxcba
no match
59 |
abcdfe
no match
60 |
ab c dfe
no match
61 |
a z a
no match
62 |
asdfg
no match
63 |
asd f g
no match
64 |
poqwoieruytjhfg
no match
65 |
66 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
67 |
68 | 69 | 72 | 73 | 74 | 75 | 76 | 85 | 92 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /challenge4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Four 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Four

13 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |

This weeks Regex Tuesday Challenge is to write part of a MarkDown parser - turn italic MarkDown (*this is italic*) into HTML italic: <em>this is italic</em>. It should not, however, match bold text - text surrounded by multiple asterisks.

28 |

This is a somewhat unrealistic challenge - in real life, you wouldn't have to make sure that it isn't bold, as you would have already parsed the bold text.

29 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

30 | 31 |

32 | 33 | 34 |

35 | 36 |

Test cases (0/11)

37 |
38 |
This text is not italic.
This text is not italic.
39 |
*This text is italic.*
<em>This text is italic.</em>
40 |
This text is *partially* italic
This text is <em>partially</em> italic
41 |
This text has *two* *italic* bits
This text has <em>two</em> <em>italic</em> bits
42 |
**bold text (not italic)**
**bold text (not italic)**
43 |
**bold text with *italic* **
**bold text with <em>italic</em> **
44 |
**part bold,** *part italic*
**part bold,** <em>part italic</em>
45 |
*italic text **with bold** *
<em>italic text **with bold** </em>
46 |
*italic* **bold** *italic* **bold**
<em>italic</em> **bold** <em>italic</em> **bold**
47 |
*invalid markdown (do not parse)**
*invalid markdown (do not parse)**
48 |
random *asterisk
random *asterisk
49 |
50 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
51 |
52 | 53 | 56 | 57 | 58 | 59 | 60 | 69 | 76 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /challenge1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week One 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week One

13 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |

This weeks Regex Tuesday challenge, the first challenge, is to make a regex which finds and highlights repeated words in a body of text. It is a fairly easy challenge, and future challenges will usually be trickier.

28 |

You should just wrap the repeated word in a <strong> element. For example, this is is a test should be turned into this is <strong>is</strong> a test.

29 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

30 | 31 |

32 | 33 | 34 |

35 | 36 |

Test cases (0/11)

37 |
38 |
This is a test
This is a test
39 |
This is is a test
This is <strong>is</strong> a test
40 |
This test test is is
This test <strong>test</strong> is <strong>is</strong>
41 |
This test is a test
This test is a test
42 |
This this test is a test
This <strong>this</strong> test is a test
43 |
cat dog dog cat dog
cat dog <strong>dog</strong> cat dog
44 |
This test is a test tester
This test is a test tester
45 |
hello world hello world
hello world hello world
46 |
This nottest test is something
This nottest test is something
47 |
This is IS a test
This is <strong>IS</strong> a test
48 |
<Mack> I'll I'll be be back back in in a a bit bit.
<Mack> I'll <strong>I'll</strong> be <strong>be</strong> back <strong>back</strong> in <strong>in</strong> a <strong>a</strong> bit <strong>bit</strong>.
49 |
50 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
51 |
52 | 53 | 56 | 57 | 58 | 59 | 60 | 69 | 76 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /challenge5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Five 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Five

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

The fifth Regex Tuesday challenge is to write a regular expressions which matches correctly formatted (with correct thousand seperators and decimal places). It should be able to match both main number syntaxes (10,000,000.45 and 10 000 000,45), and should not match invalid numbers such as 123.456.789.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/31)

37 |
38 |
124
match
39 |
1,024
match
40 |
2,000,204
match
41 |
3,000.6
match
42 |
8,205,500.4672
match
43 |
0.5
match
44 |
36,000.57
match
45 |
100,000
match
46 |
5
match
47 |
46
match
48 |
10.444444444444
match
49 | 50 |
1 024
match
51 |
9 999 352
match
52 |
10,19836
match
53 |
30 000,7302
match
54 |
0,5
match
55 |
47 372
match
56 | 57 |
.5
no match
58 |
1025
no match (no seperator)
59 |
1,5826,000
no match
60 |
,046
no match
61 |
100.
no match
62 |
2.2.2
no match
63 |
10,
no match
64 |
10,.5
no match
65 | 66 |
507
no match
67 |
507
no match
68 |
34 34
no match
69 |
3692 38
no match
70 |
36 047.
no match
71 |
47 .7
no match
72 |
73 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
74 |
75 | 76 | 79 | 80 | 81 | 82 | 83 | 92 | 99 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /challenge8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Eight 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Eight

13 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |

This challenge is a hybrid of challenge #1 - matching repeated words - and challenge #4, a basic MarkDown parser. The challenge is to match (immediately) repeating MarkDown list items! Check out the examples - it is easier to look at them than to have it explained.

28 |

Repeated items should be wrapped in double asterisks, for MarkDown bold. The second * List item should be replaced with * **List item**

29 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

30 | 31 |

32 | 33 | 34 |

35 | 36 |

Test cases (0/10)

37 |
38 |
* First list item
* Second list item
* First list item
* Second list item
39 |
* Repeated list item
* Repeated list item
* Repeated list item
* **Repeated list item**
40 |
* First list item
* Repeated list item
* Repeated list item
* Final list item
* First list item
* Repeated list item
* **Repeated list item**
* Final list item
41 |
* First * First
* First * First
42 |
* First * First
* First * First
* First * First
* **First * First**
43 |
* First repeated
* First repeated
* Second repeated
* Second repeated
* First repeated
* **First repeated**
* Second repeated
* **Second repeated**
44 |
* Not repeated yet
* Second
* Not repeated yet
* Not repeated yet
* Second
* Not repeated yet
45 |
* Not
* Not repeated
* Repeated
* Repeated
* Not
* Not repeated
* Repeated
* **Repeated**
46 |
* Two spaces before second bullet
* Two spaces before second bullet
* Two spaces before second bullet
* **Two spaces before second bullet**
47 |
* Case insensitive
* CASE inSensiTIVE
* Case insensitive
* **CASE inSensiTIVE**
48 |
49 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
50 |
51 | 52 | 55 | 56 | 57 | 58 | 59 | 68 | 75 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /challenge9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Nine 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Nine

13 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |

Another MarkDown challenge! This challenge is simply to parse MarkDown links - so [text](http://example.com) would simply be replaced with the following HTML: <a href="http://example.com">text</a>.

28 |

Be careful with images. ![alt text](image location) should be left alone, as it isn't a link.

29 |

If you don't want to write an expression for URLs too, you can see answers to the previous challenge on URLs on Reddit.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 | 35 |

36 | 37 |

Test cases (0/17)

38 |
39 |
[Basic link](http://example.com)
<a href="http://example.com">Basic link</a>
40 |
[Another](http://example.com/)
<a href="http://example.com/">Another</a>
41 |
Link: [lynx.io](http://lynx.io/)
Link: <a href="http://lynx.io/">lynx.io</a>
42 |
[Text](http://test.this-test.com/)
<a href="http://test.this-test.com/">Text</a>
43 |
[Test!](http://this-test.test.com) hello
<a href="http://this-test.test.com">Test!</a> hello
44 |
l [l](http://TESTdomain.com) l
l <a href="http://TESTdomain.com">l</a> l
45 |
[number](http://0test.com/)
<a href="http://0test.com/">number</a>
46 |
[Invalid](invalid://example.com)
[Invalid](invalid://example.com)
47 |
[Invalid](mailto:nobody@example.com)
[Invalid](mailto:nobody@example.com)
48 |
[Invalid](javascript:alert())
[Invalid](javascript:alert())
49 |
[Invalid](http://test_ing.com)
[Invalid](http://test_ing.com)
50 |
[Invalid](http://inval.id,com)
[Invalid](http://inval.id,com)
51 |
![Image](http://example.com/cats.jpg)
![Image](http://example.com/cats.jpg)
52 |
![Other image](cats.jpg)
![Other image](cats.jpg)
53 |
l[Invalid MarkDown](http://example.com)
l[Invalid MarkDown](http://example.com)
54 |
[[Invalid MarkDown](http://example.com)
[[Invalid MarkDown](http://example.com)
55 |
[Invalid MarkDown](http://example.com)l
[Invalid MarkDown](http://example.com)l
56 |
57 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
58 |
59 | 60 | 63 | 64 | 65 | 66 | 67 | 76 | 83 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /challenge17.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Seventeen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Seventeen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

In the first challenge of 2013 after the holidays, you have to match valid regular expressions. This challenge will be in several parts - in the first, you only have to match literal characters, character classes, and a few other minor features, and in future weeks I will be adding more features until we can accurately match nearly every regular expression.

30 |

To see what regex features must be supported, it would probably be better to look at the test cases. The features that must be matched are literal characters, character classes, and the following operators: .?+*. The global and case insensitive operators should also be matched.

31 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

32 | 33 |

34 | 35 |

36 | 37 |

Test cases (0/43)

38 |
39 |
/regex/
match
40 |
/regexp?/
match
41 |
/regexp?/g
match
42 |
/regexp?/gi
match
43 |
/ab?c+/i
match
44 |
/ab*c+/g
match
45 |
/a[bc]+/
match
46 |
/a?[bc]?/i
match
47 |
/[bc]*/
match
48 |
/[]/
match
49 |
/[]+/
match
50 |
/[]?/g
match
51 |
/r?e?x*/
match
52 |
/[**]/
match
53 |
/[**]*/
match
54 |
/[Rr]eg[Ee]xp?/
match
55 |
/[ab][cd]+/
match
56 |
/regex+?/
match
57 |
/regex*?/
match
58 |
/a\/a/
match
59 |
/\*/g
match
60 |
/\?/i
match
61 |
/\+/i
match
62 |
/\??/
match
63 |
/\?+/g
match
64 |
/[?]+/
match
65 |
/regex??/
match
66 | 67 |
regex
no match
68 |
regex?
no match
69 |
//
no match
70 |
/*/
no match
71 |
/+/
no match
72 |
/?/
no match
73 |
/regex?+/
no match
74 |
/regex*+/
no match
75 |
/regex/n
no match
76 |
/regex/*
no match
77 |
/a/a/
no match
78 |
/\/
no match
79 |
/\\\/
no match
80 |
/[Rr]egE**xp?/
no match
81 |
/[Rr]egExp?+/
no match
82 |
/[Rr]++egExp?/
no match
83 |
84 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
85 |
86 | 87 | 90 | 91 | 92 | 93 | 94 | 103 | 110 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /challenge2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Two 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Two

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

The second Regex Tuesday challenge is slightly trickier challenge. Unlike the last challenge, it is to match something, not to replace something.

30 |

In this challenge, you are aiming to match a grayscale CSS colour. It should be able to match anything but the colour names (eg "red"). See the test cases below for examples.

31 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

32 |

If you're finding this challenge too tricky, you can simplify it - for example, to match all the hex colours (eg "#000"), and then move onto the rgb colours. hsl can be a bit trickier - do as much or as little as you can. For an explanation of the various colour syntaxes available, check out this article. Good luck!

33 | 34 |

35 | 36 |

37 | 38 |

Test cases (0/40)

39 |
40 |
#000
match
41 |
#aaa
match
42 |
#eEe
match
43 |
#111111
match
44 |
#6F6F6F
match
45 |
#efEfEF
match
46 |
rgb(0, 0, 0)
match
47 |
rgb(15,15,15)
match
48 |
rgb(2.5, 2.5,2.5)
match
49 |
rgb(1, 01, 000001)
match
50 |
rgb(20%, 20%,20%)
match
51 |
rgba(4,4,4,0.8)
match
52 |
rgba(4,4, 4,1 )
match
53 |
rgba(3,3,3,0.12536)
match
54 |
rgba(10%,10%,10%,5%)
match
55 |
hsl(20,0%, 50%)
match
56 |
hsl(0, 10%, 100%)
match
57 |
hsl(0.5, 10.5%, 0%)
match
58 |
hsl(5, 5%, 0%)
match
59 |
hsla(20, 0%, 50%, 0.88)
match
60 |
hsla(0, 0%, 0%, 0.25)
match
61 | 62 |
#ef4
no match
63 |
#eEf
no match
64 |
#11111e
no match
65 |
#123456
no match
66 |
rgb(2, 4, 7)
no match
67 |
rgb(10, 10,100)
no match
68 |
rgb(1.5%, 1.5%, 1.6%)
no match
69 |
rgba(1, 01, 0010, 0.5)
no match
70 |
hsl(20, 20%, 20%)
no match
71 |
hsl(0, 1%, 01%)
no match
72 |
hsla(0, 10%, 50%, 0.5)
no match
73 | 74 |
#11111
no match
75 |
#000000000
no match
76 |
rgb (1, 1, 1)
no match
77 |
rgb(10, 10, 10, 10)
no match
78 |
rgb(257, 257, 257)
no match
79 |
rgb(10%, 10, 10)
no match
80 |
hsl (20,0%, 50%)
no match
81 |
argb(1,1,1)
no match
82 |
83 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
84 |
85 | 86 | 89 | 90 | 91 | 92 | 93 | 102 | 109 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /challenge6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Six 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Six

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

Today's Regex Tuesday challenge, the sixth challenge, is to match IPv4 addresses in the syntaxes (dotted decimal, dotted hexadecimal, dotted octal, hexadecimal, decimal and octal) specified on Wikipedia. More test cases will be added to this challenge later.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/48)

37 |
38 |
192.0.2.235
match
39 |
99.198.122.146
match
40 |
18.101.25.153
match
41 |
23.71.254.72
match
42 |
100.100.100.100
match
43 |
173.194.34.134
match
44 |
212.58.241.131
match
45 |
46.51.197.88
match
46 | 47 |
0xC0.0x00.0x02.0xEB
match
48 |
0xFF.0x12.0xF1.0x1F
match
49 |
0x11.0x22.0x33.0x44
match
50 | 51 |
0300.0000.0002.0353
match
52 |
0377.0377.0377.0377
match
53 |
0100.0100.0100.0100
match
54 | 55 |
0xC00002EC
match
56 |
0xFF12F11F
match
57 |
0x11223344
match
58 | 59 |
3221226219
match
60 |
2130706433
match
61 |
287454020
match
62 |
4279431455
match
63 |
4294967295
match
64 | 65 |
030000001353
match
66 |
030000001354
match
67 |
037704570437
match
68 |
02110431504
match
69 |
037777777777
match
70 | 71 |
0300.19.0.2
match
72 |
99.0377.4.0002
match
73 |
0xFF.255.0377.0x12
match
74 | 75 |
256.256.256.256
no match
76 |
0x100.0x11.0x11.0x11
no match
77 |
0x11.0x100.0x11.0x11
no match
78 |
0xx20.0x20.0x20.0x20
no match
79 |
0180.0100.0100.0100
no match
80 |
0100.0100.0109.0100
no match
81 |
0x100111111
no match
82 |
0x111001111
no match
83 |
100.100.100
no match
84 |
0x20.0x50.0x2
no match
85 |
.100.100.100.100
no match
86 |
100..100.100.100.
no match
87 |
100.100.100.100.
no match
88 |
256.100.100.100.100
no match
89 |
100.100.100.100.0x40
no match
90 |
4294967296
no match (too big)
91 |
037777777778
no match (too big)
92 |
011377000000000000008
no match
93 |
94 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
95 |
96 | 97 | 100 | 101 | 102 | 103 | 104 | 113 | 120 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /challenge7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Seven 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Seven

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

The seventh regex tuesday challenge is to match valid domain names with protocols (http and https) in front of them and an optional slash (/) behind them. To keep it simple, you do not have to worry about special characters.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/41)

37 |
38 |
http://example.com/
match
39 |
https://example.com/
match
40 |
http://www.example.com/
match
41 |
http://example.org/
match
42 |
http://example.co.uk
match
43 |
http://bla.bla.biz
match
44 |
http://1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
match
45 |
https://boring.museum
match
46 |
http://lynx.io/
match
47 |
https://example.edu
match
48 |
http://example.gov/
match
49 |
http://sub.example.cd
match
50 |
https://personal.test.me
match
51 |
http://0test.com/
match
52 |
http://a.b
match
53 |
http://this-test.com
match
54 |
http://test.this-test.com/
match
55 |
http://this-test.test.com
match
56 |
http://TESTdomain.com
match
57 |
http://abcdefghijklmnopqrstuvwxyz.com
match
58 | 59 |
example.com
no match
60 |
www.example.com
no match
61 |
invalid://example.com
no match
62 |
httpd://example.com/
no match
63 |
ahttp://example.com
no match
64 |
javascript:alert()
no match
65 |
mailto:nobody@example.com
no match
66 |
http://test ing.com
no match
67 |
http://test'ing.com
no match
68 |
http://test_ing.com
no match
69 |
http://inval.id,com
no match
70 |
http://
no match
71 |
http://.com
no match
72 |
http://.....com
no match
73 |
http://example..com
no match
74 |
http://example.com.
no match
75 |
http://-example.com
no match
76 |
http://example-.com
no match
77 |
http://example.com-
no match
78 |
http://1234567890123456789012345678901234567890123456789012345678901234.com
no match (too long)
79 |
http://0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.com
no match (too long)
80 |
81 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
82 |
83 | 84 | 87 | 88 | 89 | 90 | 91 | 100 | 107 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /challenge10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Ten 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Ten

13 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |

We're into double figures! This challenge was /u/jordanreiter's idea; the challenge is to turn a sentence into a number of "tokens" that would be suitable for something like a search engine to use a keywords. For example, "don't tell Suzie Smith-Hopper that I broke Daniel's toy horse" would be turned into "don't,tell,Suzie,Smith-Hopper,that,I,broke,Daniel's,toy,horse" and "other "big name" items" would be turned into "other,big name, items".

28 |

The four criteria are as follows:

29 | 35 |

This challenge is challenging! It is certainly possible, though.

36 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

37 | 38 |

39 | 40 | 41 |

42 | 43 |

Test cases (0/17)

44 |
45 |
This is a test
This,is,a,test
46 |
This is another test
This,is,another,test
47 |
This "big test" is a test
This,big test,is,a,test
48 |
This "big test" is a 'big test'
This,big test,is,a,big test
49 |
Almost "this entire" thing "is just a" quote
Almost,this entire,thing,is just a,quote
50 |
Suzie Smith-Hopper
Suzie,Smith-Hopper
51 |
Suzie Smith-Hopper is test
Suzie,Smith-Hopper,is,test
52 |
Suzie Smith-Hopper is--test
Suzie,Smith-Hopper,is,test
53 |
This----is--test
This,is,test
54 |
This-----is-test
This,is-test
55 |
Don't say anything
Don't,say,anything
56 |
I can't think
I,can't,think
57 |
This' is a 'test
This,is,a,test
58 |
don't tell Suzie Smith-Hopper that I broke Daniel's toy horse
don't,tell,Suzie,Smith-Hopper,that,I,broke,Daniel's,toy,horse
59 |
I can't see Suzie Smith-Hopper anywhere; can you
I,can't,see,Suzie,Smith-Hopper,anywhere,can,you
60 |
Too long; didn't read
Too,long,didn't,read
61 |
Suzie Smith-Hopper's car was stolen
Suzie,Smith-Hopper's,car,was,stolen
62 |
63 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
64 |
65 | 66 | 69 | 70 | 71 | 72 | 73 | 82 | 89 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /challenge18.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Eighteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Eighteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

This challenge is to check to see whether a string is valid IRC message sent to a user or channel. IRC is sufficiently simple that they can be parsed with regular expressions, and proper parser is not required.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/36)

37 |
38 |
callum!callum@lynx.io PRIVMSG #chat :Hello!
match
39 |
40 |
ChanServ!ChanServ@Services. PRIVMSG callum :The message can contain anything except new lines.
match
41 |


42 |
[a]!abc@test PRIVMSG #chat :Test
match
43 |
`|\^!abc@test PRIVMSG #chat :Test
match
44 |
45 |
[_]!abc@test PRIVMSG #chat :Test
match
46 |
a0!abc@test PRIVMSG #chat :Test
match
47 |
a234567890123456!callum@lynx.io PRIVMSG #chat :Test
match
48 |
49 |
callum!call!um@lynx.io PRIVMSG #chat :Test
match
50 |
51 |
callum!cal@lum@lynx.io PRIVMSG #chat :Test
match
52 |
53 |
callum!callum@lynx.io PRIVMSG ## :Test
match
54 |
55 |
callum!callum@lynx.io PRIVMSG #a :Test
match
56 |
57 |
callum!callum@lynx.io PRIVMSG #()"';:<> :Test
match
58 |
59 |
callum!callum@lynx.io PRIVMSG #chat ::@*(£&%(*&£'[]
match
60 |

61 |
callum!callum@lynx.io PRIVMSG [a] :Test
match
62 |
63 |
callum!callum@lynx.io PRIVMSG `|\^ :Test
match
64 |
65 |
callum!callum@lynx.io PRIVMSG [_] :Test
match
66 |
67 |
callum!callum@lynx.io PRIVMSG a0 :Test
match
68 |
69 |
callum!callum@lynx.io PRIVMSG a234567890123456 :Test
match
70 |
71 |
callum!callum@lynx.io PRIVMSG #(cm) :Test
match
72 |
73 | 74 |
(cm)!callum@lynx.io PRIVMSG #chat :Hello!
no match
75 |
76 |
cm!!callum@lynx.io PRIVMSG #chat :Hello!
no match
77 |
78 |
c@m!callum@lynx.io PRIVMSG #chat :Hello!
no match
79 |
80 |
c,m!callum@lynx.io PRIVMSG #chat :Hello!
no match
81 |
82 |
c$m!callum@lynx.io PRIVMSG #chat :Hello!
no match
83 |
84 |
c.m!callum@lynx.io PRIVMSG #chat :Hello!
no match
85 |
86 |
c;m!callum@lynx.io PRIVMSG #chat :Hello!
no match
87 |
88 |
0a!abc@test PRIVMSG #chat :Test
no match
89 |
90 |
a2345678901234567!callum@lynx.io PRIVMSG #chat :Hello!
no match
91 |

92 |
callum!callum@lynx.io PRIVMSG #$ :Test
match
93 |
94 |
callum!callum@lynx.io PRIVMSG #€ :Test
match
95 |
96 |
callum!callum@lynx.io PRIVMSG cm! :Test
no match
97 |
98 |
callum!callum@lynx.io PRIVMSG (cm) :Test
no match
99 |
100 |
callum!callum@lynx.io PRIVMSG c@m :Test
no match
101 |
102 |
callum!callum@lynx.io PRIVMSG c,m :Test
no match
103 |
104 |
callum!callum@lynx.io PRIVMSG c$m :Test
no match
105 |
106 |
callum!callum@lynx.io PRIVMSG c.m :Test
no match
107 |
108 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
109 |
110 | 111 | 114 | 115 | 116 | 117 | 118 | 127 | 134 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Tuesday - Challenges 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday - Challenges

13 |
14 | 15 |
16 |
17 |
18 | 19 |
20 |
21 |
22 | 23 |
24 |

Regex Tuesday is the day where everyone writes regex for a day! Every tuesday, I will push a new challenge to this website. They can be easy or tricky, and there is sure to be a variety of different challenges available.

25 |

Thanks to GitHub for the hosting, and thanks to Koen Klaren for the design!

26 | 27 |

Challenges

28 | 29 | 111 | 112 |

There are currently two types of challenge; challenges where you have to do a find and replace on a given set of strings to produce a new string, and challenges where you have to match something. Every challenge will have a given set of "test cases". With the first type of challenge, the cases will be an input string and an expected output string, which will be compared with the actual output from your regular expression. The second type will be a string followed by "match" or "no match". The idea is to get your regex to pass as many test cases as possible - with some challenges, it'll be easy to get all test cases to pass, and with some, it'll be near impossible and you just have to get as many as you can to pass.

113 | 114 |

Future Challenges

115 | 116 |

I'll aim to post a challenge every tuesday, which I will post on Reddit / Twitter (@callumacrae) / webdevRefinery. Watching the repo on GitHub will also get you notifications.

117 |

If you have any ideas for challenges or would like to contribute a challenge, send me a message or a pull request. If you send a pull request, chances are I will merge it the tuesday afterwards.

118 |
119 | 120 | 123 | 124 | 125 | 126 | 127 | 136 | 143 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /challenge14.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Fourteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Fourteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

This challenge, suggested by /u/a-t-k, is to match all the valid chemical element short names (eg. H and Ag) of elements with an atomic number of 50 or less. This is golf; the aim is to create the shortest regular expression possible. You should match the chemical formulas, and nothing else.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/101)

37 |
38 |
H
match
39 |
He
match
40 |
Li
match
41 |
Be
match
42 |
B
match
43 |
C
match
44 |
N
match
45 |
O
match
46 |
F
match
47 |
Ne
match
48 |
Na
match
49 |
Mg
match
50 |
Ni
match
51 |
Si
match
52 |
P
match
53 |
S
match
54 |
Cl
match
55 |
Ar
match
56 |
K
match
57 |
Ca
match
58 |
Sc
match
59 |
Ti
match
60 |
V
match
61 |
Cr
match
62 |
Mn
match
63 |
Fe
match
64 |
Co
match
65 |
Ni
match
66 |
Cu
match
67 |
Zn
match
68 |
Ga
match
69 |
Ge
match
70 |
As
match
71 |
Se
match
72 |
Br
match
73 |
Kr
match
74 |
Rb
match
75 |
Sr
match
76 |
Y
match
77 |
Zr
match
78 |
Nb
match
79 |
Mo
match
80 |
Tc
match
81 |
Ru
match
82 |
Rh
match
83 |
Pd
match
84 |
Ag
match
85 |
Cd
match
86 |
In
match
87 |
Sn
match
88 | 89 |
A
no match
90 |
At
no match
91 |
Ab
no match
92 |
Ad
no match
93 |
Ba
no match
94 |
Ce
no match
95 |
D
no match
96 |
E
no match
97 |
En
no match
98 |
Fa
no match
99 |
Fu
no match
100 |
Gu
no match
101 |
Ha
no match
102 |
Hu
no match
103 |
I
no match
104 |
Is
no match
105 |
J
no match
106 |
Ka
no match
107 |
Kb
no match
108 |
L
no match
109 |
La
no match
110 |
M
no match
111 |
Ma
no match
112 |
Ob
no match
113 |
Op
no match
114 |
Pa
no match
115 |
Pb
no match
116 |
Pe
no match
117 |
Pg
no match
118 |
Po
no match
119 |
Q
no match
120 |
Qs
no match
121 |
R
no match
122 |
Rs
no match
123 |
Sb
no match
124 |
St
no match
125 |
Ta
no match
126 |
Te
no match
127 |
U
no match
128 |
Ub
no match
129 |
Up
no match
130 |
Vw
no match
131 |
W
no match
132 |
Wv
no match
133 |
X
no match
134 |
Xe
no match
135 |
Xp
no match
136 |
Ya
no match
137 |
Yg
no match
138 |
Z
no match
139 |
Za
no match
140 |
141 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
142 |
143 | 144 | 147 | 148 | 149 | 150 | 151 | 160 | 167 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /challenge15.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Fifteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Fifteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

This challenge, also suggested by /u/a-t-k (as was last weeks), is to match musical chord names such as Cmin, Bmaj. You should match both the long and short forms, and you can find an explanation of the different chords here (the examples section is probably the quickest to understand). For this challenge, we will assume that E♯, B♯, F♭ and C♭ don't exist. We will also only be matching sixth and seventh chords.

30 |

Note that the sharp sign: is not a hash sign: #.

31 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

32 | 33 |

34 | 35 |

36 | 37 |

Test cases (0/89)

38 |
39 |
C
match
40 |
E
match
41 |
G
match
42 |
A
match
43 |
B♭
match

44 |
F♯
match

45 |
D
match
46 |
Cmaj
match
47 |
E♭M
match

48 |
Dmin
match
49 |
Fmin
match
50 |
Em
match
51 |
E♭m
match

52 |
E+
match
53 |
G+
match
54 |
B♭+
match

55 |
Aaug
match
56 |
B♭aug
match

57 |
match
58 |
B♭°
match

59 |
Edim
match
60 |
Fdim
match
61 |
C6
match
62 |
Cmaj6
match
63 |
Dmin6
match
64 |
D7
match
65 |
Ddom7
match
66 |
Fmaj7
match
67 |
Gmin7
match
68 |
C♯6
match

69 |
FM6
match
70 |
Gm7
match
71 |
C♯m6
match

72 |
Dm6
match
73 |
F+7
match
74 |
B+7
match
75 |
E♭+7
match

76 |
Eaug7
match
77 |
Aaug7
match
78 |
G♭aug7
match

79 |
match
80 |
match
81 |
G♭ø
match

82 |
Eø7
match
83 |
Fø7
match
84 |
F♯ø7
match

85 | 86 |
Z
no match
87 |
H
no match
88 |
I
no match
89 |
F♭
no match

90 |
C♭
no match

91 |
E♯
no match

92 |
B♯
no match

93 |
Imaj
no match
94 |
ZM
no match
95 |
E♯M
no match

96 |
F♭maj
no match

97 |
Jmin
no match
98 |
E♯m
no match

99 |
F♭aug
no match

100 |
J+
no match
101 |
E♯+
no match

102 |
E♯dim
no match

103 |
C♭°
no match

104 |
B♯6
no match

105 |
H6
no match
106 |
Z7
no match
107 |
C5
no match
108 |
A3
no match
109 |
Ddom8
no match
110 |
F9
no match
111 |
B2
no match
112 |
Bm♯6
no match

113 |
HM6
no match
114 |
Zm7
no match
115 |
CMaj5
no match
116 |
Am3
no match
117 |
DM8
no match
118 |
Fmin9
no match
119 |
BM2
no match
120 |
J+7
no match
121 |
E♯+7
no match

122 |
Jaug7
no match
123 |
E♯aug7
no match

124 |
Cdom6
no match
125 |
Ddom6
no match
126 |
F♭ø
no match

127 |
Fø6
no match
128 |
Fø8
no match
129 |
130 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
131 |
132 | 133 | 136 | 137 | 138 | 139 | 140 | 149 | 156 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /challenge20.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Twenty 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Twenty

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

Challenge number twenty is to match valid chess move notation using the algebraic notation (other challenges in the future will be for other notations), as explained by this article. You don't need to worry about the moves being valid, which is not possible in regex alone. Don't worry about analysis (!!, !, etc.)

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/103)

37 |
38 |
e4
match
39 |
a8
match
40 |
g5
match
41 |
h7
match
42 |
a1
match
43 |
Kd2
match
44 |
Kg6
match
45 |
Qh4
match
46 |
Qe2
match
47 |
Qb7
match
48 |
Nf2
match
49 |
Nc6
match
50 |
Be4
match
51 |
Bf3
match
52 |
Bb2
match
53 |
Ra1
match
54 |
Rc3
match
55 |
Rh8
match
56 |
0-0
match
57 |
0-0-0
match
58 |
exd5
match
59 |
axb7
match
60 |
exd2
match
61 |
Bxc6
match
62 |
Bxa4
match
63 |
Qxe2
match
64 |
Qxb7
match
65 |
Nxf2
match
66 |
Nxb2
match
67 |
Bxb2
match
68 |
Rxh8
match
69 |
Rxc3
match
70 |
exd5(ep)
match
71 |
exd2(ep)
match
72 |
a1=Q
match
73 |
d1=Q
match
74 |
f8=Q
match
75 |
e8=Q
match
76 |
a1=N
match
77 |
b8=B
match
78 |
f1=R
match
79 |
d8=Q
match
80 |
bxc1=Q
match
81 |
exd1=Q
match
82 |
Raxc1
match
83 |
Rfxd2
match
84 |
R2xc1
match
85 |
R5xd2
match
86 |
Bxc6+
match
87 |
Rxh8+
match
88 |
Rh8+
match
89 |
Bxb2+
match
90 |
Rxc3++
match
91 |
Bxc6++
match
92 |
d8=Q++
match
93 | 94 |
2
no match
95 |
b
no match
96 |
i2
no match
97 |
a9
no match
98 |
5d
no match
99 |
K2
no match
100 |
Ki6
no match
101 |
Kf9
no match
102 |
Qp3
no match
103 |
Qd9
no match
104 |
Q3
no match
105 |
N
no match
106 |
Nz9
no match
107 |
Na10
no match
108 |
B2
no match (watch case)
109 |
Bb
no match
110 |
Bi4
no match
111 |
Ri5
no match
112 |
Ra9
no match
113 |
Sa2
no match
114 |
Zf3
no match
115 |
Jj2
no match
116 |
1-1
no match
117 |
0
no match
118 |
2-1
no match
119 |
0-1
no match
120 |
0-0-1
no match
121 |
0-0-0-0
no match
122 |
0--0
no match
123 |
bxa9
no match
124 |
hxi2
no match
125 |
Kxf9
no match
126 |
Qxp3
no match
127 |
Nxz9
no match
128 |
Bxi4
no match
129 |
Rxi5
no match
130 |
a1=
no match
131 |
a2=Q
no match
132 |
b4=N
no match
133 |
d1=S
no match
134 |
d5=G
no match
135 |
exd5=G
no match
136 |
exd1=S
no match
137 |
bxa1=
no match
138 |
Rdxd2
no match
139 |
Rexe2
no match
140 |
R2xe2
no match
141 |
Bxi4++
no match
142 |
143 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
144 |
145 | 146 | 149 | 150 | 151 | 152 | 153 | 162 | 169 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /challenge16.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Sixteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Sixteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

This is the second part of Challenge #14, Chemical Element Golf. This is pretty much the same thing, but instead of matching elements with atomic numbers up to 50, you must match the elements with chemical numbers of above 50 (there are more than 50 of them this time, too).

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/135)

37 |
38 |
Sn
match
39 |
Sb
match
40 |
Te
match
41 |
I
match
42 |
Xe
match
43 |
Cs
match
44 |
Ba
match
45 |
La
match
46 |
Ce
match
47 |
Pr
match
48 |
Nd
match
49 |
Pm
match
50 |
Sm
match
51 |
Eu
match
52 |
Gd
match
53 |
Tb
match
54 |
Dy
match
55 |
Ho
match
56 |
Er
match
57 |
Tm
match
58 |
Yb
match
59 |
Lu
match
60 |
Hf
match
61 |
Ta
match
62 |
W
match
63 |
Re
match
64 |
Os
match
65 |
Ir
match
66 |
Pt
match
67 |
Au
match
68 |
Hg
match
69 |
Tl
match
70 |
Pb
match
71 |
Bi
match
72 |
Po
match
73 |
At
match
74 |
Rn
match
75 |
Fr
match
76 |
Ra
match
77 |
Ac
match
78 |
Th
match
79 |
Pa
match
80 |
U
match
81 |
Np
match
82 |
Pu
match
83 |
Am
match
84 |
Cm
match
85 |
Bk
match
86 |
Cf
match
87 |
Es
match
88 |
Fm
match
89 |
Md
match
90 |
No
match
91 |
Lr
match
92 | 93 |
A
no match
94 |
Ab
no match
95 |
Ad
no match
96 |
B
no match
97 |
Bf
no match
98 |
Bh
no match
99 |
C
no match
100 |
Ca
no match
101 |
Cu
no match
102 |
Ck
no match
103 |
D
no match
104 |
Du
no match
105 |
Dud
no match
106 |
E
no match
107 |
Ef
no match
108 |
Egg
no match
109 |
F
no match
110 |
Fp
no match
111 |
Fk
no match
112 |
G
no match
113 |
Gg
no match
114 |
Gi
no match
115 |
H
no match
116 |
Hk
no match
117 |
Hl
no match
118 |
Hn
no match
119 |
J
no match
120 |
Ja
no match
121 |
Js
no match
122 |
Jz
no match
123 |
K
no match
124 |
Kf
no match
125 |
Km
no match
126 |
Ks
no match
127 |
L
no match
128 |
Lm
no match
129 |
Ln
no match
130 |
M
no match
131 |
Ma
no match
132 |
Me
no match
133 |
Ml
no match
134 |
N
no match
135 |
Na
no match
136 |
Nf
no match
137 |
O
no match
138 |
Of
no match
139 |
Oof
no match
140 |
P
no match
141 |
Ph
no match
142 |
Py
no match
143 |
Q
no match
144 |
Qa
no match
145 |
Qm
no match
146 |
R
no match
147 |
Rf
no match
148 |
S
no match
149 |
Sa
no match
150 |
Sr
no match
151 |
Ss
no match
152 |
T
no match
153 |
To
no match
154 |
Ts
no match
155 |
Uc
no match
156 |
Ur
no match
157 |
Uu
no match
158 |
Uuc
no match
159 |
Uun
no match
160 |
Uum
no match
161 |
V
no match
162 |
Vv
no match
163 |
Vx
no match
164 |
X
no match
165 |
Xr
no match
166 |
Xj
no match
167 |
Y
no match
168 |
Ye
no match
169 |
Yea
no match
170 |
Z
no match
171 |
Za
no match
172 |
Zm
no match
173 |
Zz
no match
174 |
175 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
176 |
177 | 178 | 181 | 182 | 183 | 184 | 185 | 194 | 201 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /challenge19.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Regex Challenge - Week Nineteen 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Regex Tuesday Challenge - Week Nineteen

13 | 14 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 |

Challenge number nineteen is another golf challenge; in this challenge, you must match all the valid HTML tag names in as few characters as possible. You match only valid tag names - more failing test cases may be added later.

30 |

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

31 | 32 |

33 | 34 |

35 | 36 |

Test cases (0/168)

37 |
38 |
a
match
39 |
abbr
match
40 |
address
match
41 |
area
match
42 |
article
match
43 |
aside
match
44 |
audio
match
45 |
b
match
46 |
base
match
47 |
bdi
match
48 |
bdo
match
49 |
blockquote
match
50 |
body
match
51 |
br
match
52 |
button
match
53 |
canvas
match
54 |
caption
match
55 |
cite
match
56 |
code
match
57 |
col
match
58 |
colgroup
match
59 |
command
match
60 |
datalist
match
61 |
dd
match
62 |
del
match
63 |
details
match
64 |
dfn
match
65 |
div
match
66 |
dl
match
67 |
dt
match
68 |
em
match
69 |
embed
match
70 |
fieldset
match
71 |
figcaption
match
72 |
figure
match
73 |
footer
match
74 |
form
match
75 |
h1
match
76 |
h2
match
77 |
h3
match
78 |
h4
match
79 |
h5
match
80 |
h6
match
81 |
head
match
82 |
header
match
83 |
hgroup
match
84 |
hr
match
85 |
html
match
86 |
i
match
87 |
iframe
match
88 |
img
match
89 |
input
match
90 |
ins
match
91 |
kbd
match
92 |
keygen
match
93 |
label
match
94 |
legend
match
95 |
li
match
96 |
link
match
97 |
map
match
98 |
mark
match
99 |
menu
match
100 |
meta
match
101 |
meter
match
102 |
nav
match
103 |
noscript
match
104 |
object
match
105 |
ol
match
106 |
optgroup
match
107 |
option
match
108 |
output
match
109 |
p
match
110 |
param
match
111 |
pre
match
112 |
progress
match
113 |
q
match
114 |
rp
match
115 |
rt
match
116 |
ruby
match
117 |
s
match
118 |
samp
match
119 |
script
match
120 |
section
match
121 |
select
match
122 |
small
match
123 |
source
match
124 |
span
match
125 |
strong
match
126 |
style
match
127 |
sub
match
128 |
summary
match
129 |
sup
match
130 |
table
match
131 |
tbody
match
132 |
td
match
133 |
textarea
match
134 |
tfoot
match
135 |
th
match
136 |
thead
match
137 |
time
match
138 |
title
match
139 |
tr
match
140 |
track
match
141 |
u
match
142 |
ul
match
143 |
var
match
144 |
video
match
145 |
wbr
match
146 | 147 |
ab
no match
148 |
acronym
no match
149 |
applet
no match
150 |
az
no match
151 |
ba
no match
152 |
basefont
no match
153 |
big
no match
154 |
c
no match
155 |
center
no match
156 |
d
no match
157 |
dad
no match
158 |
dir
no match
159 |
e
no match
160 |
eb
no match
161 |
f
no match
162 |
font
no match
163 |
frame
no match
164 |
frameset
no match
165 |
g
no match
166 |
ga
no match
167 |
gurtrood
no match
168 |
h
no match
169 |
h0
no match
170 |
h7
no match
171 |
h10
no match
172 |
in
no match
173 |
j
no match
174 |
jam
no match
175 |
k
no match
176 |
key
no match
177 |
l
no match
178 |
la
no match
179 |
m
no match
180 |
man
no match
181 |
n
no match
182 |
o
no match
183 |
old
no match
184 |
put
no match
185 |
queen
no match
186 |
r
no match
187 |
rn
no match
188 |
slower
no match
189 |
strike
no match
190 |
t
no match
191 |
tab
no match
192 |
tf
no match
193 |
tt
no match
194 |
un
no match
195 |
v
no match
196 |
vw
no match
197 |
vehicle
no match
198 |
w
no match
199 |
weird
no match
200 |
x
no match
201 |
xx
no match
202 |
y
no match
203 |
yahooa
no match
204 |
z
no match
205 |
zebra
no match
206 |
zebras
no match
207 |
208 |
Congratulations, your regex passes all the test cases! Remember to share this challenge.
209 |
210 | 211 | 214 | 215 | 216 | 217 | 218 | 227 | 234 | 245 | 246 | 247 | --------------------------------------------------------------------------------