Add languages Russian, Arabic, Chinese, Portuguese (#18305)

This commit is contained in:
Beau Carnes
2018-10-10 18:03:03 -04:00
committed by mrugesh mohapatra
parent 09d3eca712
commit 2ca3a2093f
5517 changed files with 371466 additions and 5 deletions

View File

@ -0,0 +1,57 @@
---
id: 587d7dba367417b2b2512ba8
title: Check for All or None
challengeType: 1
videoUrl: ''
localeTitle: 检查全部或无
---
## Description
<section id="description">有时,您要搜索的模式可能包含可能存在或可能不存在的模式。但是,尽管如此,检查它们可能很重要。您可以指定可能存在带问号的元素, <code>?</code> 。这将检查前一个元素中的零个或一个。您可以将此符号视为前一个元素是可选的。例如,美式英语和英式英语略有不同,您可以使用问号来匹配两种拼写。 <blockquote>让美国人=“颜色”; <br>让british =“color”; <br>让rainbowRegex = / colour /; <br> rainbowRegex.test美国; //返回true <br> rainbowRegex.test英国; //返回true </blockquote></section>
## Instructions
<section id="instructions">更改正则表达式<code>favRegex</code>以匹配该单词的美国英语(收藏)和英国英语(收藏)版本。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用可选的符号, <code>?</code> 。
testString: 'assert(favRegex.source.match(/\?/).length > 0, "Your regex should use the optional symbol, <code>?</code>.");'
- text: 你的正则表达式应该匹配<code>&quot;favorite&quot;</code>
testString: 'assert(favRegex.test("favorite"), "Your regex should match <code>"favorite"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;favourite&quot;</code>
testString: 'assert(favRegex.test("favourite"), "Your regex should match <code>"favourite"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;fav&quot;</code>
testString: 'assert(!favRegex.test("fav"), "Your regex should not match <code>"fav"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let favWord = "favorite";
let favRegex = /change/; // Change this line
let result = favRegex.test(favWord);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db4367417b2b2512b92
title: Extract Matches
challengeType: 1
videoUrl: ''
localeTitle: 提取匹配
---
## Description
<section id="description">到目前为止,您只是检查字符串中是否存在模式。您还可以使用<code>.match()</code>方法提取您找到的实际匹配项。要使用<code>.match()</code>方法,请将该方法应用于字符串并传入括号内的正则表达式。这是一个例子: <blockquote> “你好,世界!”。匹配(/ Hello /; <br> //返回[“Hello”] <br>让ourStr =“正则表达式”; <br>让ourRegex = / expressions /; <br> ourStr.matchourRegex; <br> //返回[“表达式”] </blockquote></section>
## Instructions
<section id="instructions">应用<code>.match()</code>方法来提取单词<code>coding</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>result</code>应该有单词<code>coding</code>
testString: 'assert(result.join() === "coding", "The <code>result</code> should have the word <code>coding</code>");'
- text: 你的regex <code>codingRegex</code>应该搜索<code>coding</code>
testString: 'assert(codingRegex.source === "coding", "Your regex <code>codingRegex</code> should search for <code>coding</code>");'
- text: 您应该使用<code>.match()</code>方法。
testString: 'assert(code.match(/\.match\(.*\)/), "You should use the <code>.match()</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,51 @@
---
id: 587d7db6367417b2b2512b9b
title: Find Characters with Lazy Matching
challengeType: 1
videoUrl: ''
localeTitle: 查找具有延迟匹配的字符
---
## Description
<section id="description">在正则表达式中, <code>greedy</code>匹配找到符合正则表达式模式的字符串的最长部分,并将其作为匹配返回。替代方案称为<code>lazy</code>匹配它找到满足正则表达式模式的字符串的最小可能部分。您可以将regex <code>/t[az]*i/</code>应用于字符串<code>&quot;titanic&quot;</code> 。这个正则表达式基本上是一个以<code>t</code>开头的模式,以<code>i</code>结尾,并且在它们之间有一些字母。默认情况下,正则表达式是<code>greedy</code> ,因此匹配将返回<code>[&quot;titani&quot;]</code> 。它找到可能适合模式的最大子串。但是,你可以使用<code>?</code>字符将其更改为<code>lazy</code>匹配。 <code>&quot;titanic&quot;</code>与调整后的正则表达式匹配<code>/t[az]*?i/</code> return <code>[&quot;ti&quot;]</code></section>
## Instructions
<section id="instructions">修复regex <code>/&lt;.*&gt;/</code>以返回HTML标记<code>&lt;h1&gt;</code>而不是文本<code>&quot;&lt;h1&gt;Winter is coming&lt;/h1&gt;&quot;</code> 。记住通配符<code>.</code>在正则表达式中匹配任何字符。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>result</code>变量应该是一个包含<code>&lt;h1&gt;</code>的数组
testString: 'assert(result[0] == "<h1>", "The <code>result</code> variable should be an array with <code>&lt;h1&gt;</code> in it");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*>/; // Change this line
let result = text.match(myRegex);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,57 @@
---
id: 587d7db4367417b2b2512b93
title: Find More Than the First Match
challengeType: 1
videoUrl: ''
localeTitle: 找到比第一场比赛更多的东西
---
## Description
<section id="description">到目前为止,您只能提取或搜索一次模式。 <blockquote>让testStr =“重复,重复,重复”; <br>让ourRegex = /重复/; <br> testStr.matchourRegex; <br> //返回[“重复”] </blockquote>要多次搜索或提取模式,可以使用<code>g</code>标志。 <blockquote> let repeatRegex = / Repeat / g; <br> testStr.matchrepeatRegex; <br> //返回[“重复”,“重复”,“重复”] </blockquote></section>
## Instructions
<section id="instructions">使用正则表达式<code>starRegex</code> ,找到并提取字符串<code>twinkleStar</code> <code>&quot;Twinkle&quot;</code>单词。 <strong>注意</strong> <br>你可以在你的正则表达式上有多个标志,比如<code>/search/gi</code> </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>starRegex</code>应该使用全局标志<code>g</code>
testString: 'assert(starRegex.flags.match(/g/).length == 1, "Your regex <code>starRegex</code> should use the global flag <code>g</code>");'
- text: 你的正则表达式<code>starRegex</code>应该使用不区分大小写的标志<code>i</code>
testString: 'assert(starRegex.flags.match(/i/).length == 1, "Your regex <code>starRegex</code> should use the case insensitive flag <code>i</code>");'
- text: 您的匹配应匹配<code>&quot;Twinkle&quot;</code>一词的出现次数
testString: 'assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), "Your match should match both occurrences of the word <code>"Twinkle"</code>");'
- text: 您的匹配<code>result</code>应该包含两个元素。
testString: 'assert(result.length == 2, "Your match <code>result</code> should have two elements in it.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /change/; // Change this line
let result = twinkleStar; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,67 @@
---
id: 587d7db7367417b2b2512b9c
title: Find One or More Criminals in a Hunt
challengeType: 1
videoUrl: ''
localeTitle: 在狩猎中找到一个或多个罪犯
---
## Description
<section id="description">是时候暂停和测试你的新正则表达式写作技巧了。一群罪犯逃出监狱逃跑但你不知道有多少人。但是你知道他们和其他人在一起时会保持紧密联系。你有责任立刻找到所有的罪犯。下面是一个查看如何执行此操作的示例regex <code>/z+/</code>在连续出现一次或多次时匹配字母<code>z</code> 。它会在以下所有字符串中找到匹配项: <blockquote> “Z” <br> “ZZZZZZ” <br> “ABCzzzz” <br> “zzzzABC” <br> “abczzzzzzzzzzzzzzzzzzzzzabc” </blockquote>但它没有在以下字符串中找到匹配项,因为没有字母<code>z</code>字符: <blockquote> “” <br> “ABC” <br> “ABCABC” </blockquote></section>
## Instructions
<section id="instructions">写一个<code>greedy</code>正则表达式,在一群其他人中找到一个或多个罪犯。罪犯由大写字母<code>C</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您正则表达式应该匹配<code>one</code>犯罪(“ <code>C</code>中”), <code>&quot;C&quot;</code>
testString: 'assert("C".match(reCriminals) && "C".match(reCriminals)[0] == "C", "Your regex should match <code>one</code> criminal ("<code>C</code>") in <code>"C"</code>");'
- text: 您正则表达式应该匹配<code>two</code>罪犯(“ <code>CC</code>中”) <code>&quot;CC&quot;</code>
testString: 'assert("CC".match(reCriminals) && "CC".match(reCriminals)[0] == "CC", "Your regex should match <code>two</code> criminals ("<code>CC</code>") in <code>"CC"</code>");'
- text: 你的正则表达式应匹配<code>&quot;P1P5P4CCCP2P6P3&quot;</code>中的<code>three</code>罪犯(“ <code>CCC</code> ”)
testString: 'assert("P1P5P4CCCP2P6P3".match(reCriminals) && "P1P5P4CCCP2P6P3".match(reCriminals)[0] == "CCC", "Your regex should match <code>three</code> criminals ("<code>CCC</code>") in <code>"P1P5P4CCCP2P6P3"</code>");'
- text: 你的正则表达式应匹配<code>&quot;P6P2P7P4P5CCCCCP3P1&quot;</code>中的<code>five</code>罪犯(“ <code>CCCCC</code> ”)
testString: 'assert("P6P2P7P4P5CCCCCP3P1".match(reCriminals) && "P6P2P7P4P5CCCCCP3P1".match(reCriminals)[0] == "CCCCC", "Your regex should match <code>five</code> criminals ("<code>CCCCC</code>") in <code>"P6P2P7P4P5CCCCCP3P1"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;&quot;</code>中的任何罪犯
testString: 'assert(!reCriminals.test(""), "Your regex should not match any criminals in <code>""</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;P1P2P3&quot;</code>中的任何罪犯
testString: 'assert(!reCriminals.test("P1P2P3"), "Your regex should not match any criminals in <code>"P1P2P3"</code>");'
- text: 您正则表达式应该与<code>fifty</code>的罪犯(“ <code>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</code>中”) <code>&quot;P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3&quot;</code> 。
testString: 'assert("P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3".match(reCriminals) && "P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3".match(reCriminals)[0] == "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "Your regex should match <code>fifty</code> criminals ("<code>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</code>") in <code>"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3"</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
// example crowd gathering
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
let reCriminals = /./; // Change this line
let matchedCriminals = crowd.match(reCriminals);
console.log(matchedCriminals);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,69 @@
---
id: 587d7db4367417b2b2512b91
title: Ignore Case While Matching
challengeType: 1
videoUrl: ''
localeTitle: 匹配时忽略大小写
---
## Description
<section id="description">到目前为止,你已经看过正则表达式来进行字符串的字面匹配。但有时,您可能还希望匹配案例差异。大小写(或有时是大写字母大小写)是大写字母和小写字母之间的区别。大写的示例是<code>&quot;A&quot;</code> <code>&quot;B&quot;</code><code>&quot;C&quot;</code> 。小写的示例是<code>&quot;a&quot;</code> <code>&quot;b&quot;</code><code>&quot;c&quot;</code> 。您可以使用所谓的标志来匹配这两种情况。还有其他标志,但在这里你将专注于忽略大小写的标志 - <code>i</code>旗帜。您可以通过将其附加到正则表达式来使用它。使用此标志的示例是<code>/ignorecase/i</code> 。此正则表达式可以匹配字符串<code>&quot;ignorecase&quot;</code> <code>&quot;igNoreCase&quot;</code><code>&quot;IgnoreCase&quot;</code></section>
## Instructions
<section id="instructions">写一个正则表达式<code>fccRegex</code>来匹配<code>&quot;freeCodeCamp&quot;</code> ,无论它的情况如何。您的正则表达式不应与任何缩写或带有空格的变体匹配。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该与<code>freeCodeCamp</code>匹配
testString: 'assert(fccRegex.test("freeCodeCamp"), "Your regex should match <code>freeCodeCamp</code>");'
- text: 你的正则表达式应该与<code>FreeCodeCamp</code>匹配
testString: 'assert(fccRegex.test("FreeCodeCamp"), "Your regex should match <code>FreeCodeCamp</code>");'
- text: 你的正则表达式应该与<code>FreecodeCamp</code>匹配
testString: 'assert(fccRegex.test("FreecodeCamp"), "Your regex should match <code>FreecodeCamp</code>");'
- text: 你的正则表达式应该与<code>FreeCodecamp</code>匹配
testString: 'assert(fccRegex.test("FreeCodecamp"), "Your regex should match <code>FreeCodecamp</code>");'
- text: 你的正则表达式不应该与<code>Free Code Camp</code>不匹配
testString: 'assert(!fccRegex.test("Free Code Camp"), "Your regex should not match <code>Free Code Camp</code>");'
- text: 你的正则表达式应该与<code>FreeCOdeCamp</code>匹配
testString: 'assert(fccRegex.test("FreeCOdeCamp"), "Your regex should match <code>FreeCOdeCamp</code>");'
- text: 你的正则表达式不应该与<code>FCC</code>匹配
testString: 'assert(!fccRegex.test("FCC"), "Your regex should not match <code>FCC</code>");'
- text: 你的正则表达式应该与<code>FrEeCoDeCamp</code>匹配
testString: 'assert(fccRegex.test("FrEeCoDeCamp"), "Your regex should match <code>FrEeCoDeCamp</code>");'
- text: 你的正则表达式应该与<code>FrEeCodECamp</code>匹配
testString: 'assert(fccRegex.test("FrEeCodECamp"), "Your regex should match <code>FrEeCodECamp</code>");'
- text: 你的正则表达式应该与<code>FReeCodeCAmp</code>匹配
testString: 'assert(fccRegex.test("FReeCodeCAmp"), "Your regex should match <code>FReeCodeCAmp</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let myString = "freeCodeCamp";
let fccRegex = /change/; // Change this line
let result = fccRegex.test(myString);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,63 @@
---
id: 587d7db4367417b2b2512b90
title: Match a Literal String with Different Possibilities
challengeType: 1
videoUrl: ''
localeTitle: 匹配具有不同可能性的文字字符串
---
## Description
<section id="description">使用<code>/coding/</code>等正则表达式,可以在另一个字符串中查找<code>&quot;coding&quot;</code>模式。这对搜索单个字符串很有用,但它仅限于一种模式。您可以使用<code>alternation</code><code>OR</code>运算符搜索多个模式: <code>|</code> 。此运算符在其之前或之后匹配模式。例如,如果你想匹配<code>&quot;yes&quot;</code><code>&quot;no&quot;</code> ,你想要的正则表达式是<code>/yes|no/</code> 。您还可以搜索两种以上的模式。您可以通过添加更多模式来实现此操作,其中更多<code>OR</code>运算符将它们分开,例如<code>/yes|no|maybe/</code></section>
## Instructions
<section id="instructions">完成正则表达式<code>petRegex</code>以匹配宠物<code>&quot;dog&quot;</code> <code>&quot;cat&quot;</code> <code>&quot;bird&quot;</code><code>&quot;fish&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;John has a pet dog.&quot;</code>返回<code>true</code> <code>&quot;John has a pet dog.&quot;</code>
testString: 'assert(petRegex.test("John has a pet dog."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"John has a pet dog."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;Emma has a pet rock.&quot;</code>返回<code>false</code> <code>&quot;Emma has a pet rock.&quot;</code>
testString: 'assert(!petRegex.test("Emma has a pet rock."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Emma has a pet rock."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;Emma has a pet bird.&quot;</code>返回<code>true</code> <code>&quot;Emma has a pet bird.&quot;</code>
testString: 'assert(petRegex.test("Emma has a pet bird."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Emma has a pet bird."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该返回<code>true</code>为字符串<code>&quot;Liz has a pet cat.&quot;</code>
testString: 'assert(petRegex.test("Liz has a pet cat."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Liz has a pet cat."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该返回<code>false</code>为<code>&quot;Kara has a pet dolphin.&quot;</code>的字符串<code>&quot;Kara has a pet dolphin.&quot;</code>
testString: 'assert(!petRegex.test("Kara has a pet dolphin."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Kara has a pet dolphin."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该返回<code>true</code>为字符串<code>&quot;Alice has a pet fish.&quot;</code>
testString: 'assert(petRegex.test("Alice has a pet fish."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Alice has a pet fish."</code>");'
- text: 你的正则表达式<code>petRegex</code>应该返回<code>false</code>为字符串<code>&quot;Jimmy has a pet computer.&quot;</code>
testString: 'assert(!petRegex.test("Jimmy has a pet computer."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Jimmy has a pet computer."</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let petString = "James has a pet cat.";
let petRegex = /change/; // Change this line
let result = petRegex.test(petString);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,61 @@
---
id: 587d7db7367417b2b2512b9f
title: Match All Letters and Numbers
challengeType: 1
videoUrl: ''
localeTitle: 匹配所有字母和数字
---
## Description
<section id="description">使用字符类,您可以使用<code>[az]</code>搜索字母表中的所有字母。这种字符类很常见,它有一个快捷方式,虽然它还包含一些额外的字符。 JavaScript中与字母表匹配的最接近的字符类是<code>\w</code> 。此快捷方式等于<code>[A-Za-z0-9_]</code> 。此字符类匹配大写和小写字母加数字。注意,此字符类还包括下划线字符( <code>_</code> )。 <blockquote>让longHand = / [A-Za-z0-9 _] + /; <br>让shortHand = / \ w + /; <br>让数字=“42”; <br> let varNames =“important_var”; <br> longHand.test数字; //返回true <br> shortHand.test数字; //返回true <br> longHand.testvarNames; //返回true <br> shortHand.testvarNames; //返回true </blockquote>这些快捷方式字符类也称为<code>shorthand character classes</code></section>
## Instructions
<section id="instructions">使用速记字符类<code>\w</code>来计算各种引号和字符串中的字母数字字符数。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(alphabetRegexV2.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该使用速记字符
testString: 'assert(/\\w/.test(alphabetRegexV2.source), "Your regex should use the shorthand character <code>\w</code> to match all characters which are alphanumeric.");'
- text: 你的正则表达式应该在<code>&quot;The five boxing wizards jump quickly.&quot;</code>找到31个字母数字字符<code>&quot;The five boxing wizards jump quickly.&quot;</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: 你的正则表达式应该在<code>&quot;Pack my box with five dozen liquor jugs.&quot;</code>找到32个字母数字字符<code>&quot;Pack my box with five dozen liquor jugs.&quot;</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: 你的正则表达式应该在<code>&quot;How vexingly quick daft zebras jump!&quot;</code>找到30个字母数字字符<code>&quot;How vexingly quick daft zebras jump!&quot;</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: 你的正则表达式应该在<code>&quot;123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.&quot;</code>找到36个字母数字字符<code>&quot;123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.&quot;</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>

View File

@ -0,0 +1,65 @@
---
id: 587d7db8367417b2b2512ba1
title: Match All Non-Numbers
challengeType: 1
videoUrl: ''
localeTitle: 匹配所有非数字
---
## Description
<section id="description">最后一项挑战显示了如何使用带有小写<code>d</code>的快捷键<code>\d</code>来搜索数字。您也可以使用类似的使用大写<code>D</code>快捷方式搜索非数字。查找非数字字符的快捷方式是<code>\D</code>这等于字符类<code>[^0-9]</code> 它查找不是0到9之间的数字的单个字符。 </section>
## Instructions
<section id="instructions">使用非数字<code>\D</code>的速记字符类来计算电影标题中有多少个非数字。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您的正则表达式应使用快捷方式字符来匹配非数字字符
testString: 'assert(/\\D/.test(noNumRegex.source), "Your regex should use the shortcut character to match non-digit characters");'
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(noNumRegex.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该在<code>&quot;9&quot;</code>找不到非数字。
testString: 'assert("9".match(noNumRegex) == null, "Your regex should find no non-digits in <code>"9"</code>.");'
- text: 你的正则表达式应该在<code>&quot;Catch 22&quot;</code>找到6个非数字。
testString: 'assert("Catch 22".match(noNumRegex).length == 6, "Your regex should find 6 non-digits in <code>"Catch 22"</code>.");'
- text: 你的正则表达式应该在<code>&quot;101 Dalmatians&quot;</code>找到11个非数字。
testString: 'assert("101 Dalmatians".match(noNumRegex).length == 11, "Your regex should find 11 non-digits in <code>"101 Dalmatians"</code>.");'
- text: '你的正则表达式应该在<code>&quot;One, Two, Three&quot;</code>找到15个非数字。'
testString: 'assert("One, Two, Three".match(noNumRegex).length == 15, "Your regex should find 15 non-digits in <code>"One, Two, Three"</code>.");'
- text: 你的正则表达式应该在<code>&quot;21 Jump Street&quot;</code>找到12个非数字。
testString: 'assert("21 Jump Street".match(noNumRegex).length == 12, "Your regex should find 12 non-digits in <code>"21 Jump Street"</code>.");'
- text: '你的正则表达式应该在<code>&quot;2001: A Space Odyssey&quot;</code>找到17个非数字。'
testString: 'assert("2001: A Space Odyssey".match(noNumRegex).length == 17, "Your regex should find 17 non-digits in <code>"2001: A Space Odyssey"</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let numString = "Your sandwich will be $5.00";
let noNumRegex = /change/; // Change this line
let result = numString.match(noNumRegex).length;
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,65 @@
---
id: 5d712346c441eddfaeb5bdef
title: Match All Numbers
challengeType: 1
videoUrl: ''
localeTitle: 匹配所有号码
---
## Description
<section id="description">您已经学习了常用字符串模式(如字母数字)的快捷方式。另一种常见模式是寻找数字或数字。查找数字字符的快捷方式是<code>\d</code> ,小写<code>d</code> 。这等于字符类<code>[0-9]</code> 它查找0到9之间任意数字的单个字符。 </section>
## Instructions
<section id="instructions">使用速记字符类<code>\d</code>来计算电影标题中的位数。写出的数字(“六”而不是六)不计算在内。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您的正则表达式应使用快捷方式字符来匹配数字字符
testString: 'assert(/\\d/.test(numRegex.source), "Your regex should use the shortcut character to match digit characters");'
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(numRegex.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该在<code>&quot;9&quot;</code>找到1位数。
testString: 'assert("9".match(numRegex).length == 1, "Your regex should find 1 digit in <code>"9"</code>.");'
- text: 你的正则表达式应该在<code>&quot;Catch 22&quot;</code>找到2位数字。
testString: 'assert("Catch 22".match(numRegex).length == 2, "Your regex should find 2 digits in <code>"Catch 22"</code>.");'
- text: 你的正则表达式应该在<code>&quot;101 Dalmatians&quot;</code>找到3位数字。
testString: 'assert("101 Dalmatians".match(numRegex).length == 3, "Your regex should find 3 digits in <code>"101 Dalmatians"</code>.");'
- text: '你的正则表达式应该在<code>&quot;One, Two, Three&quot;</code>找不到数字。'
testString: 'assert("One, Two, Three".match(numRegex) == null, "Your regex should find no digits in <code>"One, Two, Three"</code>.");'
- text: 您的正则表达式应该在<code>&quot;21 Jump Street&quot;</code>找到2位数字。
testString: 'assert("21 Jump Street".match(numRegex).length == 2, "Your regex should find 2 digits in <code>"21 Jump Street"</code>.");'
- text: '你的正则表达式应该在<code>&quot;2001: A Space Odyssey&quot;</code>找到4位数字。'
testString: 'assert("2001: A Space Odyssey".match(numRegex).length == 4, "Your regex should find 4 digits in <code>"2001: A Space Odyssey"</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let numString = "Your sandwich will be $5.00";
let numRegex = /change/; // Change this line
let result = numString.match(numRegex).length;
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,69 @@
---
id: 587d7db5367417b2b2512b94
title: Match Anything with Wildcard Period
challengeType: 1
videoUrl: ''
localeTitle: 匹配通配符期间的任何内容
---
## Description
<section id="description">有时您不会(或不需要)知道模式中的确切字符。想到所有匹配的单词,比如拼写错误需要很长时间。幸运的是,您可以使用通配符来节省时间: <code>.</code>通配符<code>.</code>将匹配任何一个字符。通配符也称为<code>dot</code><code>period</code> 。您可以像使用正则表达式中的任何其他字符一样使用通配符。例如,如果你想匹配<code>&quot;hug&quot;</code> <code>&quot;huh&quot;</code> <code>&quot;hut&quot;</code><code>&quot;hum&quot;</code> ,你可以使用正则表达式<code>/hu./</code>来匹配所有四个单词。 <blockquote>让humStr =“我会哼唱一首歌”; <br>让hugStr =“熊抱”; <br>让huRegex = /hu./; <br> humStr.matchhuRegex; //返回[“hum”] <br> hugStr.matchhuRegex; //返回[“拥抱”] </blockquote></section>
## Instructions
<section id="instructions">完成正则表达式<code>unRegex</code> ,使其匹配字符串<code>&quot;run&quot;</code> <code>&quot;sun&quot;</code> <code>&quot;fun&quot;</code> <code>&quot;pun&quot;</code> <code>&quot;nun&quot;</code><code>&quot;bun&quot;</code> 。你的正则表达式应该使用通配符。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您应该使用<code>.test()</code>方法。
testString: 'assert(code.match(/\.test\(.*\)/), "You should use the <code>.test()</code> method.");'
- text: 您应该在正则表达式<code>unRegex</code>使用通配符
testString: 'assert(/\./.test(unRegex.source), "You should use the wildcard character in your regex <code>unRegex</code>");'
- text: 你的正则表达式<code>unRegex</code>应该匹配<code>&quot;run&quot;</code> <code>&quot;Let us go on a run.&quot;</code> <code>&quot;run&quot;</code>中的<code>&quot;run&quot;</code> <code>&quot;Let us go on a run.&quot;</code>
testString: 'assert(unRegex.test("Let us go on a run."), "Your regex <code>unRegex</code> should match <code>"run"</code> in <code>"Let us go on a run."</code>");'
- text: 你的正则表达式<code>unRegex</code>应该与<code>&quot;sun&quot;</code> <code>&quot;The sun is out today.&quot;</code> <code>&quot;sun&quot;</code>中的<code>&quot;sun&quot;</code>匹配<code>&quot;The sun is out today.&quot;</code>
testString: 'assert(unRegex.test("The sun is out today."), "Your regex <code>unRegex</code> should match <code>"sun"</code> in <code>"The sun is out today."</code>");'
- text: 你的正则表达式<code>unRegex</code>应该与<code>&quot;fun&quot;</code> <code>&quot;Coding is a lot of fun.&quot;</code> <code>&quot;fun&quot;</code>中的<code>&quot;fun&quot;</code>匹配<code>&quot;Coding is a lot of fun.&quot;</code>
testString: 'assert(unRegex.test("Coding is a lot of fun."), "Your regex <code>unRegex</code> should match <code>"fun"</code> in <code>"Coding is a lot of fun."</code>");'
- text: 你的正则表达式<code>unRegex</code>应该匹配<code>&quot;pun&quot;</code> <code>&quot;Seven days without a pun makes one weak.&quot;</code> <code>&quot;pun&quot;</code> <code>&quot;Seven days without a pun makes one weak.&quot;</code>
testString: 'assert(unRegex.test("Seven days without a pun makes one weak."), "Your regex <code>unRegex</code> should match <code>"pun"</code> in <code>"Seven days without a pun makes one weak."</code>");'
- text: 你的正则表达式<code>unRegex</code>应该与<code>&quot;nun&quot;</code> <code>&quot;One takes a vow to be a nun.&quot;</code> <code>&quot;nun&quot;</code>中的<code>&quot;nun&quot;</code>匹配<code>&quot;One takes a vow to be a nun.&quot;</code>
testString: 'assert(unRegex.test("One takes a vow to be a nun."), "Your regex <code>unRegex</code> should match <code>"nun"</code> in <code>"One takes a vow to be a nun."</code>");'
- text: 你的正则表达式<code>unRegex</code>应该匹配<code>&quot;bun&quot;</code> <code>&quot;She got fired from the hot dog stand for putting her hair in a bun.&quot;</code> <code>&quot;bun&quot;</code>中的<code>&quot;bun&quot;</code> <code>&quot;She got fired from the hot dog stand for putting her hair in a bun.&quot;</code>
testString: 'assert(unRegex.test("She got fired from the hot dog stand for putting her hair in a bun."), "Your regex <code>unRegex</code> should match <code>"bun"</code> in <code>"She got fired from the hot dog stand for putting her hair in a bun."</code>");'
- text: 您的正则表达式<code>unRegex</code>不应与<code>&quot;There is a bug in my code.&quot;</code>匹配<code>&quot;There is a bug in my code.&quot;</code>
testString: 'assert(!unRegex.test("There is a bug in my code."), "Your regex <code>unRegex</code> should not match <code>"There is a bug in my code."</code>");'
- text: 您的正则表达式<code>unRegex</code>不应该匹配<code>&quot;Catch me if you can.&quot;</code>
testString: 'assert(!unRegex.test("Can me if you can."), "Your regex <code>unRegex</code> should not match <code>"Catch me if you can."</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /change/; // Change this line
let result = unRegex.test(exampleStr);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,57 @@
---
id: 587d7db7367417b2b2512b9d
title: Match Beginning String Patterns
challengeType: 1
videoUrl: ''
localeTitle: 匹配开始字符串模式
---
## Description
<section id="description">先前的挑战表明,正则表达式可用于寻找许多匹配。它们还用于搜索字符串中特定位置的模式。在之前的挑战中,您使用<code>character set</code>内的<code>caret</code>符( <code>^</code> )来创建<code>[^thingsThatWillNotBeMatched]</code>形式的<code>negated character set</code> 。在<code>character set</code> <code>caret</code>用于在字符串的开头搜索模式。 <blockquote>让firstString =“Ricky是第一个可以找到。”; <br>让firstRegex = / ^ Ricky /; <br> firstRegex.testfirstString; <br> //返回true <br>让notFirst =“你现在找不到Ricky了。”; <br> firstRegex.testnotFirst; <br> //返回false </blockquote></section>
## Instructions
<section id="instructions">使用正则表达式中的<code>caret</code>只能在字符串<code>rickyAndCal</code>的开头找到<code>&quot;Cal&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该用大写字母搜索<code>&quot;Cal&quot;</code> 。
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for <code>"Cal"</code> with a capital letter.");'
- text: 你的正则表达式不应该使用任何标志。
testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
- text: 你的正则表达式应该匹配字符串开头的<code>&quot;Cal&quot;</code> 。
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match <code>"Cal"</code> at the beginning of the string.");'
- text: 您的正则表达式不应与字符串中间的<code>&quot;Cal&quot;</code>匹配。
testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match <code>"Cal"</code> in the middle of a string.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db6367417b2b2512b99
title: Match Characters that Occur One or More Times
challengeType: 1
videoUrl: ''
localeTitle: 匹配出现一次或多次的字符
---
## Description
<section id="description">有时,您需要匹配连续出现一次或多次的字符(或字符组)。这意味着它至少发生一次,并且可以重复。您可以使用<code>+</code>字符来检查是否是这种情况。请记住,角色或模式必须连续出现。也就是说,角色必须一个接一个地重复。例如, <code>/a+/g</code>会在<code>&quot;abc&quot;</code>找到一个匹配并返回<code>[&quot;a&quot;]</code> 。由于<code>+</code> ,它也会在<code>&quot;aabc&quot;</code>找到一个匹配并返回<code>[&quot;aa&quot;]</code> 。如果它是检查字符串<code>&quot;abab&quot;</code> ,它会找到两个匹配并返回<code>[&quot;a&quot;, &quot;a&quot;]</code>因为<code>a</code>字符不在一行 - 它们之间有一个<code>b</code> 。最后,由于字符串<code>&quot;bcd&quot;</code>没有<code>&quot;a&quot;</code> <code>&quot;bcd&quot;</code> ,因此找不到匹配项。 </section>
## Instructions
<section id="instructions">您希望在<code>&quot;Mississippi&quot;</code>字母<code>s</code>出现一次或多次时找到匹配项。写一个使用<code>+</code>符号的正则表达式。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>myRegex</code>应该使用<code>+</code>符号来匹配一个或多个<code>s</code>字符。
testString: 'assert(/\+/.test(myRegex.source), "Your regex <code>myRegex</code> should use the <code>+</code> sign to match one or more <code>s</code> characters.");'
- text: 你的正则表达式<code>myRegex</code>应该匹配2个项目。
testString: 'assert(result.length == 2, "Your regex <code>myRegex</code> should match 2 items.");'
- text: <code>result</code>变量应该是一个包含两个匹配<code>&quot;ss&quot;</code>的数组
testString: 'assert(result[0] == "ss" && result[1] == "ss", "The <code>result</code> variable should be an array with two matches of <code>"ss"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let difficultSpelling = "Mississippi";
let myRegex = /change/; // Change this line
let result = difficultSpelling.match(myRegex);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,59 @@
---
id: 587d7db6367417b2b2512b9a
title: Match Characters that Occur Zero or More Times
challengeType: 1
videoUrl: ''
localeTitle: 匹配出现零次或多次的字符
---
## Description
<section id="description">最后一项挑战使用加<code>+</code>号来查找出现一次或多次的字符。还有一个选项可以匹配出现零次或多次的字符。执行此操作的字符是<code>asterisk</code><code>star</code> <code>asterisk</code> <code>*</code><blockquote>让soccerWord =“gooooooooal”; <br>让gPhrase =“直觉”; <br>让oPhrase =“越过月亮”; <br> let goRegex = / go * /; <br> soccerWord.matchgoRegex; //返回[“goooooooo”] <br> gPhrase.matchgoRegex; //返回[“g”] <br> oPhrase.matchgoRegex; //返回null </blockquote></section>
## Instructions
<section id="instructions">创建一个正则表达式<code>chewieRegex</code>使用的<code>*</code>字符匹配所有上下<code>&quot;a&quot;</code>中的字符<code>chewieQuote</code> 。你的正则表达式不需要标志,它不应该与任何其他引号相匹配。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您正则表达式<code>chewieRegex</code>应该使用<code>*</code>字符匹配零个或多个<code>a</code>字符。
testString: 'assert(/\*/.test(chewieRegex.source), "Your regex <code>chewieRegex</code> should use the <code>*</code> character to match zero or more <code>a</code> characters.");'
- text: 你的正则表达式<code>chewieRegex</code>应匹配16个字符。
testString: 'assert(result[0].length === 16, "Your regex <code>chewieRegex</code> should match 16 characters.");'
- text: 你的正则表达式应该匹配<code>&quot;Aaaaaaaaaaaaaaaa&quot;</code> 。
testString: 'assert(result[0] === "Aaaaaaaaaaaaaaaa", "Your regex should match <code>"Aaaaaaaaaaaaaaaa"</code>.");'
- text: '你的正则表达式不应该与<code>&quot;He made a fair move. Screaming about it can&#39;t help you.&quot;</code>中的任何角色相匹配<code>&quot;He made a fair move. Screaming about it can&#39;t help you.&quot;</code>'
testString: 'assert(!"He made a fair move. Screaming about it can\"t help you.".match(chewieRegex), "Your regex should not match any characters in <code>"He made a fair move. Screaming about it can&#39t help you."</code>");'
- text: '你的正则表达式不应该与<code>&quot;Let him have it. It&#39;s not wise to upset a Wookiee.&quot;</code>中的任何角色相匹配<code>&quot;Let him have it. It&#39;s not wise to upset a Wookiee.&quot;</code>'
testString: 'assert(!"Let him have it. It\"s not wise to upset a Wookiee.".match(chewieRegex), "Your regex should not match any characters in <code>"Let him have it. It&#39s not wise to upset a Wookiee."</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /change/; // Change this line
let result = chewieQuote.match(chewieRegex);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db7367417b2b2512b9e
title: Match Ending String Patterns
challengeType: 1
videoUrl: ''
localeTitle: 匹配结束字符串模式
---
## Description
<section id="description">在上一个挑战中,您学会了使用<code>caret</code>来搜索字符串开头的模式。还有一种方法可以在字符串末尾搜索模式。您可以使用正则表达式末尾的<code>dollar sign</code>字符<code>$</code>来搜索字符串的结尾。 <blockquote>让theEnding =“这是一个永无止境的故事”; <br>让storyRegex = / story $ /; <br> storyRegex.testtheEnding; <br> //返回true <br>让noEnding =“有时故事必须结束”; <br> storyRegex.testnoEnding; <br> //返回false <br></blockquote></section>
## Instructions
<section id="instructions">使用锚字符( <code>$</code> )来匹配字符串<code>&quot;caboose&quot;</code>在字符串的结尾<code>caboose</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您应该在正则表达式中使用美元符号<code>$</code> anchor搜索<code>&quot;caboose&quot;</code> 。
testString: 'assert(lastRegex.source == "caboose$", "You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.");'
- text: 你的正则表达式不应该使用任何标志。
testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
- text: 您应该在字符串末尾匹配<code>&quot;caboose&quot;</code> <code>&quot;The last car on a train is the caboose&quot;</code>
testString: 'assert(lastRegex.test("The last car on a train is the caboose"), "You should match <code>"caboose"</code> at the end of the string <code>"The last car on a train is the caboose"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,61 @@
---
id: 587d7db8367417b2b2512ba0
title: Match Everything But Letters and Numbers
challengeType: 1
videoUrl: ''
localeTitle: 匹配一切,但字母和数字
---
## Description
<section id="description">您已经了解到可以使用快捷键来匹配使用<code>\w</code>字母数字<code>[A-Za-z0-9_]</code> 。您可能想要搜索的自然模式与字母数字相反。您可以使用<code>\W</code>搜索<code>\w</code>的反面。注意,相反的模式使用大写字母。此快捷方式与<code>[^A-Za-z0-9_]</code><blockquote>让shortHand = / \ W /; <br>让数字=“42”; <br> let sentence =“Coding”; <br> numbers.match简写; //返回[“%”] <br> sentence.match简写; //返回[“!”] <br></blockquote></section>
## Instructions
<section id="instructions">使用速记字符类<code>\W</code>来计算各种引号和字符串中的非字母数字字符数。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(nonAlphabetRegex.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该在<code>&quot;The five boxing wizards jump quickly.&quot;</code>找到6个非字母数字字符<code>&quot;The five boxing wizards jump quickly.&quot;</code> 。
testString: 'assert("The five boxing wizards jump quickly.".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>.");'
- text: 你的正则表达式应该使用速记字符。
testString: 'assert(/\\W/.test(nonAlphabetRegex.source), "Your regex should use the shorthand character to match characters which are non-alphanumeric.");'
- text: 你的正则表达式应该在<code>&quot;Pack my box with five dozen liquor jugs.&quot;</code>找到8个非字母数字字符<code>&quot;Pack my box with five dozen liquor jugs.&quot;</code>
testString: 'assert("Pack my box with five dozen liquor jugs.".match(nonAlphabetRegex).length == 8, "Your regex should find 8 non-alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>");'
- text: 你的正则表达式应该在<code>&quot;How vexingly quick daft zebras jump!&quot;</code>找到6个非字母数字字符<code>&quot;How vexingly quick daft zebras jump!&quot;</code>
testString: 'assert("How vexingly quick daft zebras jump!".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>");'
- text: 你的正则表达式应该在<code>&quot;123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.&quot;</code>找到12个非字母数字字符<code>&quot;123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.&quot;</code>
testString: 'assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(nonAlphabetRegex).length == 12, "Your regex should find 12 non-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 nonAlphabetRegex = /change/; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db5367417b2b2512b96
title: Match Letters of the Alphabet
challengeType: 1
videoUrl: ''
localeTitle: 匹配字母的字母
---
## Description
<section id="description">您了解了如何使用<code>character sets</code>来指定要匹配的一组字符,但是当您需要匹配大范围的字符(例如,字母表中的每个字母)时,这是很多类型。幸运的是,有一个内置功能,使这简短。在<code>character set</code> ,您可以使用<code>hyphen</code>字符来定义要匹配的<code>hyphen</code>范围: <code>-</code> 。例如,要匹配小写字母<code>a</code><code>e</code>您将使用<code>[ae]</code><blockquote>让catStr =“猫”; <br>让batStr =“蝙蝠”; <br>让matStr =“mat”; <br>让bgRegex = / [ae] at /; <br> catStr.matchbgRegex; //返回[“cat”] <br> batStr.matchbgRegex; //返回[“bat”] <br> matStr.matchbgRegex; //返回null </blockquote></section>
## Instructions
<section id="instructions">匹配字符串<code>quoteSample</code>中的所有字母。 <strong>注意</strong> <br>务必匹配大写和小写<strong>字母<strong></strong></strong> </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>alphabetRegex</code>应该匹配35项。
testString: 'assert(result.length == 35, "Your regex <code>alphabetRegex</code> should match 35 items.");'
- text: 你的正则表达式<code>alphabetRegex</code>应该使用全局标志。
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex <code>alphabetRegex</code> should use the global flag.");'
- text: 你的正则表达式<code>alphabetRegex</code>应该使用不区分大小写的标志。
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex <code>alphabetRegex</code> should use the case insensitive flag.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let quoteSample = "The quick brown fox jumps over the lazy dog.";
let alphabetRegex = /change/; // Change this line
let result = alphabetRegex; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db3367417b2b2512b8f
title: Match Literal Strings
challengeType: 1
videoUrl: ''
localeTitle: 匹配文字字符串
---
## Description
<section id="description">在上一次挑战中,您使用正则表达式<code>/Hello/</code>搜索了单词<code>&quot;Hello&quot;</code> 。该正则表达式搜索字符串<code>&quot;Hello&quot;</code>的文字匹配。这是另一个搜索字符串<code>&quot;Kevin&quot;</code>的文字匹配的示例: <blockquote>让testStr =“你好,我的名字是凯文。”; <br>让testRegex = / Kevin /; <br> testRegex.testtestStr; <br> //返回true </blockquote>任何其他形式的<code>&quot;Kevin&quot;</code>都不匹配。例如,正则表达式<code>/Kevin/</code>将不匹配<code>&quot;kevin&quot;</code><code>&quot;KEVIN&quot;</code><blockquote> let wrongRegex = / kevin /; <br> wrongRegex.testtestStr; <br> //返回false </blockquote>未来的挑战将展示如何匹配其他形式。 </section>
## Instructions
<section id="instructions">完成正则表达式<code>waldoRegex</code>在字符串<code>waldoIsHiding</code>使用文字匹配查找<code>&quot;Waldo&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>waldoRegex</code>应该找到<code>&quot;Waldo&quot;</code>
testString: 'assert(waldoRegex.test(waldoIsHiding), "Your regex <code>waldoRegex</code> should find <code>"Waldo"</code>");'
- text: 你的正则表达式<code>waldoRegex</code>不应该搜索任何其他内容。
testString: 'assert(!waldoRegex.test("Somewhere is hiding in this text."), "Your regex <code>waldoRegex</code> should not search for anything else.");'
- text: 您应该与正则表达式执行文字字符串匹配。
testString: 'assert(!/\/.*\/i/.test(code), "You should perform a literal string match with your regex.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /search/; // Change this line
let result = waldoRegex.test(waldoIsHiding);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,59 @@
---
id: 587d7db9367417b2b2512ba4
title: Match Non-Whitespace Characters
challengeType: 1
videoUrl: ''
localeTitle: 匹配非空白字符
---
## Description
<section id="description">您学会了使用<code>\s</code>搜索空格,并使用小写<code>s</code> 。您还可以搜索除空格之外的所有内容。使用<code>\S</code>搜索非空格, <code>\S</code>是一个大写的<code>s</code> 。此模式将不匹配空格,回车符,制表符,换页符和换行符。你可以认为它类似于字符类<code>[^ \r\t\f\n\v]</code><blockquote>让whiteSpace =“空白。到处都是空白!” <br>让nonSpaceRegex = / \ S / g; <br> whiteSpace.matchnonSpaceRegex。长度; //返回32 </blockquote></section>
## Instructions
<section id="instructions">更改正则表达式<code>countNonWhiteSpace</code>以在字符串中查找多个非空白字符。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(countNonWhiteSpace.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该使用速记字符
testString: 'assert(/\\S/.test(countNonWhiteSpace.source), "Your regex should use the shorthand character <code>\S/code> to match all non-whitespace characters.");'
- text: 你的正则表达式应该在<code>&quot;Men are from Mars and women are from Venus.&quot;</code>找到35个非空格<code>&quot;Men are from Mars and women are from Venus.&quot;</code>
testString: 'assert("Men are from Mars and women are from Venus.".match(countNonWhiteSpace).length == 35, "Your regex should find 35 non-spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: '你的正则表达式应该在<code>&quot;Space: the final frontier.&quot;</code>找到23个非空格<code>&quot;Space: the final frontier.&quot;</code>'
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23, "Your regex should find 23 non-spaces in <code>"Space: the final frontier."</code>");'
- text: 你的正则表达式应该在<code>&quot;MindYourPersonalSpace&quot;</code>找到21个非空格
testString: 'assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21, "Your regex should find 21 non-spaces in <code>"MindYourPersonalSpace"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db5367417b2b2512b97
title: Match Numbers and Letters of the Alphabet
challengeType: 1
videoUrl: ''
localeTitle: 匹配数字和字母的字母
---
## Description
<section id="description">使用连字符( <code>-</code> )匹配一系列字符不仅限于字母。它也适用于匹配一系列数字。例如, <code>/[0-5]/</code>匹配<code>0</code><code>5</code>之间的任何数字,包括<code>0</code><code>5</code> 。此外,可以在单个字符集中组合一系列字母和数字。 <blockquote>让jennyStr =“Jenny8675309”; <br>让myRegex = / [a-z0-9] / ig; <br> //匹配jennyStr中的所有字母和数字<br> jennyStr.matchmyRegex; </blockquote></section>
## Instructions
<section id="instructions">创建一个与<code>h</code><code>s</code>之间的字母范围匹配的正则表达式,以及介于<code>2</code><code>6</code>之间的数字范围。请记住在正则表达式中包含适当的标志。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>myRegex</code>应该匹配17项。
testString: 'assert(result.length == 17, "Your regex <code>myRegex</code> should match 17 items.");'
- text: 你的正则表达式<code>myRegex</code>应该使用全局标志。
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
- text: 你的正则表达式<code>myRegex</code>应该使用不区分大小写的标志。
testString: 'assert(myRegex.flags.match(/i/).length == 1, "Your regex <code>myRegex</code> should use the case insensitive flag.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let quoteSample = "Blueberry 3.141592653s are delicious.";
let myRegex = /change/; // Change this line
let result = myRegex; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,59 @@
---
id: 587d7db5367417b2b2512b95
title: Match Single Character with Multiple Possibilities
challengeType: 1
videoUrl: ''
localeTitle: 将单个角色与多种可能性相匹配
---
## Description
<section id="description">您学习了如何匹配文字模式( <code>/literal/</code> )和通配符( <code>/./</code> )。这些是正则表达式的极端,其中一个找到完全匹配,另一个匹配一切。有两个极端之间可以平衡的选项。您可以使用<code>character classes</code>搜索具有一定灵活性的文字模式。字符类允许您通过将它们放在方括号( <code>[</code><code>]</code> )括号内来定义要匹配的一组字符。例如,您想匹配<code>&quot;bag&quot;</code> <code>&quot;big&quot;</code><code>&quot;bug&quot;</code>但不匹配<code>&quot;bog&quot;</code> 。您可以创建regex <code>/b[aiu]g/</code>来执行此操作。 <code>[aiu]</code>是仅匹配字符<code>&quot;a&quot;</code> <code>&quot;i&quot;</code><code>&quot;u&quot;</code>的字符类。 <blockquote>让bigStr =“大”; <br>让bagStr =“bag”; <br>让bugStr =“bug”; <br>让bogStr =“bog”; <br>让bgRegex = / b [aiu] g /; <br> bigStr.matchbgRegex; //返回[“大”] <br> bagStr.matchbgRegex; //返回[“bag”] <br> bugStr.matchbgRegex; //返回[“bug”] <br> bogStr.matchbgRegex; //返回null </blockquote></section>
## Instructions
<section id="instructions">在正则表达式<code>vowelRegex</code>使用带元音( <code>a</code> <code>e</code> <code>i</code> <code>o</code> <code>u</code> )的字符类来查找字符串<code>quoteSample</code>中的所有元音。 <strong>注意</strong> <br>确保匹配大写和小写元音。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你应该找到所有25个元音。
testString: 'assert(result.length == 25, "You should find all 25 vowels.");'
- text: 你的正则表达式<code>vowelRegex</code>应该使用一个字符类。
testString: 'assert(/\[.*\]/.test(vowelRegex.source), "Your regex <code>vowelRegex</code> should use a character class.");'
- text: 你的正则表达式<code>vowelRegex</code>应该使用全局标志。
testString: 'assert(vowelRegex.flags.match(/g/).length == 1, "Your regex <code>vowelRegex</code> should use the global flag.");'
- text: 你的正则表达式<code>vowelRegex</code>应该使用不区分大小写的标志。
testString: 'assert(vowelRegex.flags.match(/i/).length == 1, "Your regex <code>vowelRegex</code> should use the case insensitive flag.");'
- text: 你的正则表达式不应该与任何辅音匹配。
testString: 'assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()), "Your regex should not match any consonants.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /change/; // Change this line
let result = vowelRegex; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7db6367417b2b2512b98
title: Match Single Characters Not Specified
challengeType: 1
videoUrl: ''
localeTitle: 匹配未指定的单个字符
---
## Description
<section id="description">到目前为止,您已创建了一组要匹配的字符,但您也可以创建一组您不想匹配的字符。这些类型的字符集称为<code>negated character sets</code> 。要创建<code>negated character set</code> ,请在<code>caret</code>括号后面和不想匹配的字符前放置一个<code>caret</code> <code>^</code> )。例如, <code>/[^aeiou]/gi</code>匹配所有不是元音的字符。请注意字符之类的<code>.</code> <code>!</code> <code>[</code> <code>@</code> <code>/</code>和空格匹配 - 否定元音字符集仅排除元音字符。 </section>
## Instructions
<section id="instructions">创建一个匹配所有不是数字或元音的字符的正则表达式。请记住在正则表达式中包含适当的标志。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式<code>myRegex</code>应匹配9项。
testString: 'assert(result.length == 9, "Your regex <code>myRegex</code> should match 9 items.");'
- text: 你的正则表达式<code>myRegex</code>应该使用全局标志。
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
- text: 你的正则表达式<code>myRegex</code>应该使用不区分大小写的标志。
testString: 'assert(myRegex.flags.match(/i/).length == 1, "Your regex <code>myRegex</code> should use the case insensitive flag.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let quoteSample = "3 blind mice.";
let myRegex = /change/; // Change this line
let result = myRegex; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,59 @@
---
id: 587d7db8367417b2b2512ba3
title: Match Whitespace
challengeType: 1
videoUrl: ''
localeTitle: 匹配空白
---
## Description
<section id="description">迄今为止的挑战包括匹配的字母和数字字母。您还可以匹配字母之间的空格或空格。您可以使用<code>\s</code>搜索空格,这是一个小写的<code>s</code> 。此模式不仅匹配空格,还匹配回车符,制表符,换页符和换行符。你可以认为它类似于字符类<code>[ \r\t\f\n\v]</code><blockquote>让whiteSpace =“空白。到处都是空白!” <br>让spaceRegex = / \ s / g; <br> whiteSpace.matchspaceRegex; <br> //返回[“”,“”] <br></blockquote></section>
## Instructions
<section id="instructions">更改正则表达式<code>countWhiteSpace</code>以查找字符串中的多个空格字符。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用全局标志。
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
- text: 你的正则表达式应该使用速记字符
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
- text: 你的正则表达式应该在<code>&quot;Men are from Mars and women are from Venus.&quot;</code>找到八个空格<code>&quot;Men are from Mars and women are from Venus.&quot;</code>
testString: 'assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, "Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: '你的正则表达式应该在<code>&quot;Space: the final frontier.&quot;</code>找到三个空格<code>&quot;Space: the final frontier.&quot;</code>'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, "Your regex should find three spaces in <code>"Space: the final frontier."</code>");'
- text: ''
testString: 'assert("MindYourPersonalSpace".match(countWhiteSpace) == null, "Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,65 @@
---
id: 587d7dba367417b2b2512ba9
title: Positive and Negative Lookahead
challengeType: 1
videoUrl: ''
localeTitle: 积极和消极的前瞻
---
## Description
<section id="description"> <code>Lookaheads</code>是一种模式它告诉JavaScript在字符串中向前看以进一步检查模式。当您想要在同一个字符串上搜索多个模式时这非常有用。有两种<code>lookaheads</code> <code>positive lookahead</code><code>negative lookahead</code> 。一个<code>positive lookahead</code>向前看将确保搜索模式中的元素存在,但实际上不匹配它。正向前瞻用作<code>(?=...)</code> ,其中<code>...</code>是不匹配的必需部分。另一方面, <code>negative lookahead</code>将确保搜索模式中的元素不存在。负向前瞻用作<code>(?!...)</code> ,其中<code>...</code>是您不希望在那里的模式。如果不存在负前瞻部分,则返回模式的其余部分。前瞻有点令人困惑,但一些例子会有所帮助。 <blockquote>让quit =“qu”; <br>让noquit =“qt”; <br>让quRegex = / q= u/; <br>让qRegex = / qu/; <br> quit.matchquRegex; //返回[“q”] <br> noquit.matchqRegex; //返回[“q”] </blockquote> <code>lookaheads</code>更实际用途是检查一个字符串中的两个或更多个模式。这是一个天真简单的密码检查器可以查找3到6个字符和至少一个数字 <blockquote> let password =“abc123”; <br>让checkPass = /= \ w {3,6}= \ D * \ d/; <br> checkPass.test密码; //返回true </blockquote></section>
## Instructions
<section id="instructions">使用<code>lookaheads</code><code>pwRegex</code>匹配长的时间大于5个字符并有两个连续的数字密码。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用两个积极的<code>lookaheads</code> 。
testString: 'assert(pwRegex.source.match(/\(\?=.*?\)\(\?=.*?\)/) !== null, "Your regex should use two positive <code>lookaheads</code>.");'
- text: 你的正则表达式不应该匹配<code>&quot;astronaut&quot;</code>
testString: 'assert(!pwRegex.test("astronaut"), "Your regex should not match <code>"astronaut"</code>");'
- text: 你的正则表达式不应该与<code>&quot;airplanes&quot;</code>匹配
testString: 'assert(!pwRegex.test("airplanes"), "Your regex should not match <code>"airplanes"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;banan1&quot;</code>
testString: 'assert(!pwRegex.test("banan1"), "Your regex should not match <code>"banan1"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;bana12&quot;</code>
testString: 'assert(pwRegex.test("bana12"), "Your regex should match <code>"bana12"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;abc123&quot;</code>
testString: 'assert(pwRegex.test("abc123"), "Your regex should match <code>"abc123"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;123&quot;</code>
testString: 'assert(!pwRegex.test("123"), "Your regex should not match <code>"123"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;1234&quot;</code>
testString: 'assert(!pwRegex.test("1234"), "Your regex should not match <code>"1234"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let sampleWord = "astronaut";
let pwRegex = /change/; // Change this line
let result = pwRegex.test(sampleWord);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,55 @@
---
id: 587d7dbb367417b2b2512bac
title: Remove Whitespace from Start and End
challengeType: 1
videoUrl: ''
localeTitle: 从开始和结束中删除空格
---
## Description
<section id="description">有时字符串周围的空白字符不是必需的,而是存在的。字符串的典型处理是删除字符串开头和结尾处的空格。 </section>
## Instructions
<section id="instructions">编写一个正则表达式并使用适当的字符串方法删除字符串开头和结尾的空格。 <strong>注意</strong> <br> <code>.trim()</code>方法可以在这里工作,但您需要使用正则表达式完成此挑战。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>result</code>应该等于<code>&quot;Hello, World!&quot;</code>'
testString: 'assert(result == "Hello, World!", "<code>result</code> should equal to <code>"Hello, World!"</code>");'
- text: 您不应该使用<code>.trim()</code>方法。
testString: 'assert(!code.match(/\.trim\(.*?\)/), "You should not use the <code>.trim()</code> method.");'
- text: <code>result</code>变量不应设置为等于字符串。
testString: 'assert(!code.match(/result\s*=\s*".*?"/), "The <code>result</code> variable should not be set equal to a string.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let hello = " Hello, World! ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,61 @@
---
id: 587d7db8367417b2b2512ba2
title: Restrict Possible Usernames
challengeType: 1
videoUrl: ''
localeTitle: 限制可能的用户名
---
## Description
<section id="description">用户名在互联网上随处可见。它们是用户在自己喜欢的网站上获得独特身份的原因。您需要检查数据库中的所有用户名。以下是用户在创建用户名时必须遵循的一些简单规则。 1用户名中的唯一数字必须在最后。最后可以有零个或多个。 2用户名字母可以是小写和大写。 3用户名必须至少两个字符长。双字母用户名只能使用字母字母。 </section>
## Instructions
<section id="instructions">更改正则表达式<code>userCheck</code>以适合上面列出的约束。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该与<code>JACK</code>匹配
testString: 'assert(userCheck.test("JACK"), "Your regex should match <code>JACK</code>");'
- text: 你的正则表达式不应该与<code>J</code>匹配
testString: 'assert(!userCheck.test("J"), "Your regex should not match <code>J</code>");'
- text: 你的正则表达式应该与<code>Oceans11</code>匹配
testString: 'assert(userCheck.test("Oceans11"), "Your regex should match <code>Oceans11</code>");'
- text: 你的正则表达式应该与<code>RegexGuru</code>匹配
testString: 'assert(userCheck.test("RegexGuru"), "Your regex should match <code>RegexGuru</code>");'
- text: 你的正则表达式不应该与<code>007</code>匹配
testString: 'assert(!userCheck.test("007"), "Your regex should not match <code>007</code>");'
- text: 你的正则表达式不应该匹配<code>9</code>
testString: 'assert(!userCheck.test("9"), "Your regex should not match <code>9</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let username = "JackOfAllTrades";
let userCheck = /change/; // Change this line
let result = userCheck.test(username);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,69 @@
---
id: 587d7dbb367417b2b2512baa
title: Reuse Patterns Using Capture Groups
challengeType: 1
videoUrl: ''
localeTitle: 使用捕获组重用模式
---
## Description
<section id="description">您搜索的某些模式将在字符串中多次出现。手动重复该正则表达式是浪费的。有一种更好的方法可以指定何时在字符串中有多个重复子字符串。您可以使用<code>capture groups</code>搜索重复子字符串。括号<code>(</code><code>)</code>用于查找重复子串。你把模式的正则表达式重复在括号之间。要指定重复字符串的显示位置,请使用反斜杠( <code>\</code> 然后使用数字。此数字从1开始随着您使用的每个其他捕获组而增加。一个例子是<code>\1</code>来匹配第一组。下面的示例匹配以空格分隔的两次出现的任何单词: <blockquote>让repeatStr =“正则表达式正则表达式”; <br> let repeatRegex = /\ w +\ s \ 1 /; <br> repeatRegex.testrepeatStr; //返回true <br> repeatStr.matchrepeatRegex; //返回[“regex regex”“regex”] </blockquote>对字符串使用<code>.match()</code>方法将返回一个数组,其中包含与其匹配的字符串及其捕获组。 </section>
## Instructions
<section id="instructions"><code>reRegex</code>使用<code>capture groups</code>来匹配在字符串中仅重复三次的数字,每个数字用空格分隔。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用数字的速记字符类。
testString: 'assert(reRegex.source.match(/\\d/), "Your regex should use the shorthand character class for digits.");'
- text: 您的正则表达式应该重复使用捕获组两次。
testString: 'assert(reRegex.source.match(/\\\d/g).length === 2, "Your regex should reuse the capture group twice.");'
- text: 你的正则表达式应该有两个空格来分隔这三个数字。
testString: 'assert(reRegex.source.match(/\\s/g).length === 2, "Your regex should have two spaces separating the three numbers.");'
- text: 你的正则表达式应该匹配<code>&quot;42 42 42&quot;</code> 。
testString: 'assert(reRegex.test("42 42 42"), "Your regex should match <code>"42 42 42"</code>.");'
- text: 你的正则表达式应该匹配<code>&quot;100 100 100&quot;</code> 。
testString: 'assert(reRegex.test("100 100 100"), "Your regex should match <code>"100 100 100"</code>.");'
- text: 你的正则表达式不应该匹配<code>&quot;42 42 42 42&quot;</code> 。
testString: 'assert.equal(("42 42 42 42").match(reRegex.source), null, "Your regex should not match <code>"42 42 42 42"</code>.");'
- text: 你的正则表达式不应该匹配<code>&quot;42 42&quot;</code> 。
testString: 'assert.equal(("42 42").match(reRegex.source), null, "Your regex should not match <code>"42 42"</code>.");'
- text: 你的正则表达式不应该匹配<code>&quot;101 102 103&quot;</code> 。
testString: 'assert(!reRegex.test("101 102 103"), "Your regex should not match <code>"101 102 103"</code>.");'
- text: 你的正则表达式不应该匹配<code>&quot;1 2 3&quot;</code> 。
testString: 'assert(!reRegex.test("1 2 3"), "Your regex should not match <code>"1 2 3"</code>.");'
- text: 你的正则表达式应匹配<code>&quot;10 10 10&quot;</code> 。
testString: 'assert(reRegex.test("10 10 10"), "Your regex should match <code>"10 10 10"</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let repeatNum = "42 42 42";
let reRegex = /change/; // Change this line
let result = reRegex.test(repeatNum);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,61 @@
---
id: 587d7db9367417b2b2512ba7
title: Specify Exact Number of Matches
challengeType: 1
videoUrl: ''
localeTitle: 指定完全匹配数
---
## Description
<section id="description">您可以使用大括号<code>quantity specifiers</code>的较低和较高数量的模式。有时您只需要特定数量的匹配。要指定一定数量的模式,只需在大括号之间放置一个数字。例如,要仅将单词<code>&quot;hah&quot;</code>与字母<code>a</code>匹配<code>3</code>次,您的正则表达式将为<code>/ha{3}h/</code><blockquote>让A4 =“haaaah”; <br>让A3 =“haaah”; <br>设A100 =“h”+“a”.repeat100+“h”; <br> let multipleHA = / ha {3} h /; <br> multipleHA.testA4; //返回false <br> multipleHA.testA3; //返回true <br> multipleHA.testA100; //返回false </blockquote></section>
## Instructions
<section id="instructions">只有当它有四个字母<code>m</code>时才更改正则表达式<code>timRegex</code>以匹配单词<code>&quot;Timber&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用大括号。
testString: 'assert(timRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
- text: 你的正则表达式不应该与<code>&quot;Timber&quot;</code>匹配
testString: 'assert(!timRegex.test("Timber"), "Your regex should not match <code>"Timber"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;Timmber&quot;</code>
testString: 'assert(!timRegex.test("Timmber"), "Your regex should not match <code>"Timmber"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;Timmmber&quot;</code>
testString: 'assert(!timRegex.test("Timmmber"), "Your regex should not match <code>"Timmmber"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Timmmmber&quot;</code>
testString: 'assert(timRegex.test("Timmmmber"), "Your regex should match <code>"Timmmmber"</code>");'
- text: 你的正则表达式不应该与30 <code>m</code>的<code>&quot;Timber&quot;</code>相匹配。
testString: 'assert(!timRegex.test("Ti" + "m".repeat(30) + "ber"), "Your regex should not match <code>"Timber"</code> with 30 <code>m</code>\"s in it.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let timStr = "Timmmmber";
let timRegex = /change/; // Change this line
let result = timRegex.test(timStr);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,63 @@
---
id: 587d7db9367417b2b2512ba6
title: Specify Only the Lower Number of Matches
challengeType: 1
videoUrl: ''
localeTitle: 仅指定较低的匹配数
---
## Description
<section id="description">您可以使用大括号<code>quantity specifiers</code>的较低和较高数量的模式。有时您只想指定较低数量的模式而没有上限。要仅指定较少的模式数,请保留第一个数字后跟逗号。例如,要仅匹配字符串<code>&quot;hah&quot;</code>与出现至少<code>3</code>次的字母<code>a</code> ,您的正则表达式将是<code>/ha{3,}h/</code><blockquote>让A4 =“haaaah”; <br>让A2 =“哈哈”; <br>设A100 =“h”+“a”.repeat100+“h”; <br> let multipleA = / ha {3} h /; <br> multipleA.testA4; //返回true <br> multipleA.testA2; //返回false <br> multipleA.testA100; //返回true </blockquote></section>
## Instructions
<section id="instructions">只有当它有四个或更多字母<code>z</code>时才更改正则表达式<code>haRegex</code>以匹配单词<code>&quot;Hazzah&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用大括号。
testString: 'assert(haRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
- text: 你的正则表达式不应该与<code>&quot;Hazzah&quot;</code>匹配
testString: 'assert(!haRegex.test("Hazzah"), "Your regex should not match <code>"Hazzah"</code>");'
- text: 你的正则表达式不应该与<code>&quot;Hazzzah&quot;</code>匹配
testString: 'assert(!haRegex.test("Hazzzah"), "Your regex should not match <code>"Hazzzah"</code>");'
- text: 你的正则表达应该匹配<code>&quot;Hazzzzah&quot;</code>
testString: 'assert(haRegex.test("Hazzzzah"), "Your regex should match <code>"Hazzzzah"</code>");'
- text: 你的正则表达应该匹配<code>&quot;Hazzzzzah&quot;</code>
testString: 'assert(haRegex.test("Hazzzzzah"), "Your regex should match <code>"Hazzzzzah"</code>");'
- text: 你的正则表达应该匹配<code>&quot;Hazzzzzzah&quot;</code>
testString: 'assert(haRegex.test("Hazzzzzzah"), "Your regex should match <code>"Hazzzzzzah"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Hazzah&quot;</code>和30个<code>z</code> 。
testString: 'assert(haRegex.test("Ha" + "z".repeat(30) + "ah"), "Your regex should match <code>"Hazzah"</code> with 30 <code>z</code>\"s in it.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let haStr = "Hazzzzah";
let haRegex = /change/; // Change this line
let result = haRegex.test(haStr);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,63 @@
---
id: 587d7db9367417b2b2512ba5
title: Specify Upper and Lower Number of Matches
challengeType: 1
videoUrl: ''
localeTitle: 指定上下匹配数
---
## Description
<section id="description">回想一下,您使用加号<code>+</code>来查找一个或多个字符,使用星号<code>*</code>来查找零个或多个字符。这些很方便,但有时你想要匹配一定范围的模式。您可以使用<code>quantity specifiers</code>模式的下限和上限。数量说明符与大括号( <code>{</code><code>}</code> )一起使用。您在大括号之间放置了两个数字 - 用于较低和较高的模式数。例如,为了匹配字母<code>&quot;ah&quot;</code>出现<code>3</code><code>5</code>次的字母<code>a</code> ,你的正则表达式将是<code>/a{3,5}h/</code><blockquote>让A4 =“aaaah”; <br>让A2 =“aah”; <br>令multipleA = / a {3,5} h /; <br> multipleA.testA4; //返回true <br> multipleA.testA2; //返回false </blockquote></section>
## Instructions
<section id="instructions">更改正则表达式<code>ohRegex</code>以匹配单词<code>&quot;Oh no&quot;</code>中的<code>3</code><code>6</code>字母<code>h</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你的正则表达式应该使用大括号。
testString: 'assert(ohRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
- text: 你的正则表达式不应该匹配<code>&quot;Ohh no&quot;</code>
testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match <code>"Ohh no"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Ohhh no&quot;</code>
testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match <code>"Ohhh no"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Ohhhh no&quot;</code>
testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match <code>"Ohhhh no"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Ohhhhh no&quot;</code>
testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match <code>"Ohhhhh no"</code>");'
- text: 你的正则表达式应该匹配<code>&quot;Ohhhhhh no&quot;</code>
testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match <code>"Ohhhhhh no"</code>");'
- text: 你的正则表达式不应该匹配<code>&quot;Ohhhhhhh no&quot;</code>
testString: 'assert(!ohRegex.test("Ohhhhhhh no"), "Your regex should not match <code>"Ohhhhhhh no"</code>");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let ohStr = "Ohhh no";
let ohRegex = /change/; // Change this line
let result = ohRegex.test(ohStr);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,56 @@
---
id: 587d7dbb367417b2b2512bab
title: Use Capture Groups to Search and Replace
challengeType: 1
videoUrl: ''
localeTitle: 使用捕获组进行搜索和替换
---
## Description
<section id="description">搜索很有用。但是,当它也更改(或替换)您匹配的文本时,您可以使搜索功能更强大。您可以在字符串上使用<code>.replace()</code>搜索和替换字符串中的文本。 <code>.replace()</code>的输入首先是您要搜索的正则表达式模式。第二个参数是用于替换匹配的字符串或用于执行某些操作的函数。 <blockquote> let wrongText =“天空是银色的。”; <br>让silverRegex = / silver /; <br> wrongText.replacesilverRegex“blue”; <br> //返回“天空是蓝色的”。 </blockquote>您还可以使用美元符号( <code>$</code> )访问替换字符串中的捕获组。 <blockquote> “Code Camp”.replace/\ w +\ s\ w +/&#39;$ 2 $ 1&#39;; <br> //返回“营地代码” </blockquote></section>
## Instructions
<section id="instructions">写一个正则表达式,以便它搜索字符串<code>&quot;good&quot;</code> 。然后更新<code>replaceText</code>变量,将<code>&quot;good&quot;</code>替换为<code>&quot;okey-dokey&quot;</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您应该使用<code>.replace()</code>来搜索和替换。
testString: 'assert(code.match(/\.replace\(.*\)/), "You should use <code>.replace()</code> to search and replace.");'
- text: 你的正则表达式应该改变<code>&quot;This sandwich is good.&quot;</code> <code>&quot;This sandwich is okey-dokey.&quot;</code>
testString: 'assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey", "Your regex should change <code>"This sandwich is good."</code> to <code>"This sandwich is okey-dokey."</code>");'
- text: 你不应该改变最后一行。
testString: 'assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/), "You should not change the last line.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let huhText = "This sandwich is good.";
let fixRegex = /change/; // Change this line
let replaceText = ""; // Change this line
let result = huhText.replace(fixRegex, replaceText);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>

View File

@ -0,0 +1,53 @@
---
id: 587d7db3367417b2b2512b8e
title: Using the Test Method
challengeType: 1
videoUrl: ''
localeTitle: 使用测试方法
---
## Description
<section id="description">正则表达式用于编程语言以匹配字符串的一部分。您可以创建模式来帮助您进行匹配。如果你想在字符串<code>&quot;The dog chased the cat&quot;</code>找到单词<code>&quot;the&quot;</code> ,你可以使用以下正则表达式: <code>/the/</code> 。请注意,正则表达式中不需要引号。 JavaScript有多种方法可以使用正则表达式。测试正则表达式的一种方法是使用<code>.test()</code>方法。 <code>.test()</code>方法接受正则表达式,将其应用于字符串(放在括号内),如果模式发现或不存在,则返回<code>true</code><code>false</code><blockquote>让testStr =“freeCodeCamp”; <br>让testRegex = / Code /; <br> testRegex.testtestStr; <br> //返回true </blockquote></section>
## Instructions
<section id="instructions">使用<code>.test()</code>方法在字符串<code>myString</code>上应用正则表达式<code>myRegex</code></section>
## Tests
<section id='tests'>
```yml
tests:
- text: 你应该使用<code>.test()</code>来测试正则表达式。
testString: 'assert(code.match(/myRegex.test\(\s*myString\s*\)/), "You should use <code>.test()</code> to test the regex.");'
- text: 您的结果应该返回<code>true</code> 。
testString: 'assert(result === true, "Your result should return <code>true</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex; // Change this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>