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.
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.
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.
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.
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.
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.
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.
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.
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.
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.  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.
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.
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!
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.
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.
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 |
30 |
If words are in quotes, treat them as a single separate token: eg "This "huge test" is pointless" would be changed to "this,huge test,is,pointless". This applies to both single quotes and double quotes.
31 |
Hyphenated last names (such as "Smith-Hopper") should be a single token, but words with more hyphens, or hyphens at the beginning or end of the word, should have the hyphens stripped and be treated as separate tokens: "Suzie Smith-Hopper test--hyphens" should be changed to "Suzie,Smith-Hopper,test,hyphens".
32 |
Contractions should be treated as a single token; "I can't do it" would be changed to "I,can't,do,it".
33 |
Punctuation should be removed (but not hyphens and quotes as above); "Too long; didn't read" would turn into "Too,long,didn't,read".
34 |
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.
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.
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!
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.
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.
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.
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.
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.
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.