* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
		
			
				
	
	
		
			66 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ---
 | |
| id: 587d7db7367417b2b2512b9f
 | |
| title: Match All Letters and Numbers
 | |
| challengeType: 1
 | |
| ---
 | |
| 
 | |
| ## Description
 | |
| <section id='description'>
 | |
| Using character classes, you were able to search for all letters of the alphabet with <code>[a-z]</code>. This kind of character class is common enough that there is a shortcut for it, although it includes a few extra characters as well.
 | |
| The closest character class in JavaScript to match the alphabet is <code>\w</code>. This shortcut is equal to <code>[A-Za-z0-9_]</code>. This character class matches upper and lowercase letters plus numbers. Note, this character class also includes the underscore character (<code>_</code>).
 | |
| <blockquote>let longHand = /[A-Za-z0-9_]+/;<br>let shortHand = /\w+/;<br>let numbers = "42";<br>let varNames = "important_var";<br>longHand.test(numbers); // Returns true<br>shortHand.test(numbers); // Returns true<br>longHand.test(varNames); // Returns true<br>shortHand.test(varNames); // Returns true</blockquote>
 | |
| These shortcut character classes are also known as <code>shorthand character classes</code>.
 | |
| </section>
 | |
| 
 | |
| ## Instructions
 | |
| <section id='instructions'>
 | |
| Use the shorthand character class <code>\w</code> to count the number of alphanumeric characters in various quotes and strings.
 | |
| </section>
 | |
| 
 | |
| ## Tests
 | |
| <section id='tests'>
 | |
| 
 | |
| ```yml
 | |
| tests:
 | |
|   - text: Your regex should use the global flag.
 | |
|     testString: assert(alphabetRegexV2.global, 'Your regex should use the global flag.');
 | |
|   - text: Your regex should use the shorthand character
 | |
|     testString: assert(/\\w/.test(alphabetRegexV2.source), 'Your regex should use the shorthand character <code>\w</code> to match all characters which are alphanumeric.');
 | |
|   - text: Your regex should find 31 alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>
 | |
|     testString: assert("The five boxing wizards jump quickly.".match(alphabetRegexV2).length === 31, 'Your regex should find 31 alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>');
 | |
|   - text: Your regex should find 32 alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>
 | |
|     testString: assert("Pack my box with five dozen liquor jugs.".match(alphabetRegexV2).length === 32, 'Your regex should find 32 alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>');
 | |
|   - text: Your regex should find 30 alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>
 | |
|     testString: assert("How vexingly quick daft zebras jump!".match(alphabetRegexV2).length === 30, 'Your regex should find 30 alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>');
 | |
|   - text: Your regex should find 36 alphanumeric characters in <code>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</code>
 | |
|     testString: assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(alphabetRegexV2).length === 36, 'Your regex should find 36 alphanumeric characters in <code>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</code>');
 | |
| 
 | |
| ```
 | |
| 
 | |
| </section>
 | |
| 
 | |
| ## Challenge Seed
 | |
| <section id='challengeSeed'>
 | |
| 
 | |
| <div id='js-seed'>
 | |
| 
 | |
| ```js
 | |
| let quoteSample = "The five boxing wizards jump quickly.";
 | |
| let alphabetRegexV2 = /change/; // Change this line
 | |
| let result = quoteSample.match(alphabetRegexV2).length;
 | |
| ```
 | |
| 
 | |
| </div>
 | |
| 
 | |
| 
 | |
| 
 | |
| </section>
 | |
| 
 | |
| ## Solution
 | |
| <section id='solution'>
 | |
| 
 | |
| ```js
 | |
| // solution required
 | |
| ```
 | |
| </section>
 |