<h3>Practice Set, Week 10, Simple RegEx Patterns</h3>
<p>Your task is to write the regular expression (on line 4) that will test for the existence of a sequence of three letters followed by three numbers, such as 'abc123'. (Note that 'zabc1234' also passes, since it contains a match.)</p>
<p>There are several ways to solve this - any of them that pass the test cases will do. Use the reference (and a RegEx tool such as Debuggex if that helps).</p>
<p>Remember that a regular expression starts and ends with a slash, and your expression goes in between, so you'll put your expression between the slashes provided. No quotes are necessary unless they are part of your expression.</p>
<p>For example, <code>/cscie\d/</code> will match the string "cscie" followed by any digit (although, subjectively, we prefer a 3 :-) ).</p>
<p>Test cases are provided. If your regular expression is correct, when you click "Run" the output will be <i>false, false, false, true, true, true</i>.</p>
<p>Output will appear below:</p>
<div id="output"></div>
var testStrings = ['a1', 'ab12', 'abcdef', 'abc1234', 'abc123', 'def456'];
// your regular expression goes here, between the '/' characters.
var regex = /.*[A-Z|a-z]{3}\d{3}.*/;
for (var i = 0; i < testStrings.length; i++) {
logMessage(regex.test(testStrings[i]));
}
// Utility function for logging convenience
// Logs msg to the element with given id
// If id is undefined, logs to #output
function logMessage(msg, id) {
if (!id) {
id = "output";
}
document.getElementById(id).innerHTML += msg + "<br>";
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.