* 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>
99 lines
2.6 KiB
Markdown
99 lines
2.6 KiB
Markdown
---
|
|
id: 587d7db7367417b2b2512b9f
|
|
title: Match All Letters and Numbers
|
|
challengeType: 1
|
|
forumTopicId: 301346
|
|
dashedName: match-all-letters-and-numbers
|
|
---
|
|
|
|
# --description--
|
|
|
|
Using character classes, you were able to search for all letters of the alphabet with `[a-z]`. 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 `\w`. This shortcut is equal to `[A-Za-z0-9_]`. This character class matches upper and lowercase letters plus numbers. Note, this character class also includes the underscore character (`_`).
|
|
|
|
```js
|
|
let longHand = /[A-Za-z0-9_]+/;
|
|
let shortHand = /\w+/;
|
|
let numbers = "42";
|
|
let varNames = "important_var";
|
|
longHand.test(numbers);
|
|
shortHand.test(numbers);
|
|
longHand.test(varNames);
|
|
shortHand.test(varNames);
|
|
```
|
|
|
|
All four of these `test` calls would return `true`.
|
|
|
|
These shortcut character classes are also known as <dfn>shorthand character classes</dfn>.
|
|
|
|
# --instructions--
|
|
|
|
Use the shorthand character class `\w` to count the number of alphanumeric characters in various quotes and strings.
|
|
|
|
# --hints--
|
|
|
|
Your regex should use the global flag.
|
|
|
|
```js
|
|
assert(alphabetRegexV2.global);
|
|
```
|
|
|
|
Your regex should use the shorthand character `\w` to match all characters which are alphanumeric.
|
|
|
|
```js
|
|
assert(/\\w/.test(alphabetRegexV2.source));
|
|
```
|
|
|
|
Your regex should find 31 alphanumeric characters in the string `The five boxing wizards jump quickly.`
|
|
|
|
```js
|
|
assert(
|
|
'The five boxing wizards jump quickly.'.match(alphabetRegexV2).length === 31
|
|
);
|
|
```
|
|
|
|
Your regex should find 32 alphanumeric characters in the string `Pack my box with five dozen liquor jugs.`
|
|
|
|
```js
|
|
assert(
|
|
'Pack my box with five dozen liquor jugs.'.match(alphabetRegexV2).length ===
|
|
32
|
|
);
|
|
```
|
|
|
|
Your regex should find 30 alphanumeric characters in the string `How vexingly quick daft zebras jump!`
|
|
|
|
```js
|
|
assert(
|
|
'How vexingly quick daft zebras jump!'.match(alphabetRegexV2).length === 30
|
|
);
|
|
```
|
|
|
|
Your regex should find 36 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(alphabetRegexV2)
|
|
.length === 36
|
|
);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
let quoteSample = "The five boxing wizards jump quickly.";
|
|
let alphabetRegexV2 = /change/; // Change this line
|
|
let result = quoteSample.match(alphabetRegexV2).length;
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
let quoteSample = "The five boxing wizards jump quickly.";
|
|
let alphabetRegexV2 = /\w/g; // Change this line
|
|
let result = quoteSample.match(alphabetRegexV2).length;
|
|
```
|