* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
		
			
				
	
	
		
			93 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
---
 | 
						|
id: 587d7db8367417b2b2512ba0
 | 
						|
title: Match Everything But Letters and Numbers
 | 
						|
challengeType: 1
 | 
						|
forumTopicId: 301353
 | 
						|
dashedName: match-everything-but-letters-and-numbers
 | 
						|
---
 | 
						|
 | 
						|
# --description--
 | 
						|
 | 
						|
You've learned that you can use a shortcut to match alphanumerics `[A-Za-z0-9_]` using `\w`. A natural pattern you might want to search for is the opposite of alphanumerics.
 | 
						|
 | 
						|
You can search for the opposite of the `\w` with `\W`. Note, the opposite pattern uses a capital letter. This shortcut is the same as `[^A-Za-z0-9_]`.
 | 
						|
 | 
						|
```js
 | 
						|
let shortHand = /\W/;
 | 
						|
let numbers = "42%";
 | 
						|
let sentence = "Coding!";
 | 
						|
numbers.match(shortHand);
 | 
						|
sentence.match(shortHand);
 | 
						|
```
 | 
						|
 | 
						|
The first `match` call would return the value `["%"]` and the second would return `["!"]`.
 | 
						|
 | 
						|
# --instructions--
 | 
						|
 | 
						|
Use the shorthand character class `\W` to count the number of non-alphanumeric characters in various quotes and strings.
 | 
						|
 | 
						|
# --hints--
 | 
						|
 | 
						|
Your regex should use the global flag.
 | 
						|
 | 
						|
```js
 | 
						|
assert(nonAlphabetRegex.global);
 | 
						|
```
 | 
						|
 | 
						|
Your regex should find 6 non-alphanumeric characters in the string `The five boxing wizards jump quickly.`.
 | 
						|
 | 
						|
```js
 | 
						|
assert(
 | 
						|
  'The five boxing wizards jump quickly.'.match(nonAlphabetRegex).length == 6
 | 
						|
);
 | 
						|
```
 | 
						|
 | 
						|
Your regex should use the shorthand character to match characters which are non-alphanumeric.
 | 
						|
 | 
						|
```js
 | 
						|
assert(/\\W/.test(nonAlphabetRegex.source));
 | 
						|
```
 | 
						|
 | 
						|
Your regex should find 8 non-alphanumeric characters in the string `Pack my box with five dozen liquor jugs.`
 | 
						|
 | 
						|
```js
 | 
						|
assert(
 | 
						|
  'Pack my box with five dozen liquor jugs.'.match(nonAlphabetRegex).length == 8
 | 
						|
);
 | 
						|
```
 | 
						|
 | 
						|
Your regex should find 6 non-alphanumeric characters in the string `How vexingly quick daft zebras jump!`
 | 
						|
 | 
						|
```js
 | 
						|
assert(
 | 
						|
  'How vexingly quick daft zebras jump!'.match(nonAlphabetRegex).length == 6
 | 
						|
);
 | 
						|
```
 | 
						|
 | 
						|
Your regex should find 12 non-alphanumeric characters in the string `123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.`
 | 
						|
 | 
						|
```js
 | 
						|
assert(
 | 
						|
  '123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(nonAlphabetRegex)
 | 
						|
    .length == 12
 | 
						|
);
 | 
						|
```
 | 
						|
 | 
						|
# --seed--
 | 
						|
 | 
						|
## --seed-contents--
 | 
						|
 | 
						|
```js
 | 
						|
let quoteSample = "The five boxing wizards jump quickly.";
 | 
						|
let nonAlphabetRegex = /change/; // Change this line
 | 
						|
let result = quoteSample.match(nonAlphabetRegex).length;
 | 
						|
```
 | 
						|
 | 
						|
# --solutions--
 | 
						|
 | 
						|
```js
 | 
						|
let quoteSample = "The five boxing wizards_jump quickly.";
 | 
						|
let nonAlphabetRegex = /\W/g; // Change this line
 | 
						|
let result = quoteSample.match(nonAlphabetRegex).length;
 | 
						|
```
 |