diff --git a/02-javascript-algorithms-and-data-structures/regular-expressions.json b/02-javascript-algorithms-and-data-structures/regular-expressions.json
index ce7c5a1..05ce479 100644
--- a/02-javascript-algorithms-and-data-structures/regular-expressions.json
+++ b/02-javascript-algorithms-and-data-structures/regular-expressions.json
@@ -8,21 +8,21 @@
"id": "587d7db3367417b2b2512b8e",
"title": "Using the Test Method",
"description": [
- "Regular expressions are used in programming languages to match parts of strings. You create patterns to help you do that matching.",
- "If you want to find the word \"the\" in the string \"The dog chased the cat\", you could use the following regular expression: /the/. Notice that quote marks are not required within the regular expression.",
- "JavaScript has multiple ways to use regexes. One way to test a regex is using the .test() method. The .test() method takes the regex, applies it to a string (which is placed inside the parentheses), and returns true or false if your pattern finds something or not.",
+ "在编程语言中,正则表达式用于匹配指定的字符串。通过正则表达式创建匹配模式(规则)可以帮你完成指定匹配。",
+ "如果你想要在字符串 \"The dog chased the cat\" 中匹配到 \"the\" 这个单词,你可以使用如下正则表达式:/the/。注意,正则表达式中不需要引号。",
+ "JavaScript 中有多种使用正则表达式的方法。测试正则表达式的一种方法是使用 .test() 方法。.test() 方法会把你编写的正则表达式应用到一个字符串(即括号内的内容),如果你的匹配模式成功匹配到字符,则返回 true,反之,返回 false。",
"
let testStr = \"freeCodeCamp\";", "
let testRegex = /Code/;
testRegex.test(testStr);
// Returns true
myRegex on the string myString using the .test() method."
+ "使用 .test() 方法,检测字符串 myString 是否符合正则表达式 myRegex 定义的规则。"
],
"tests": [
{
- "text": "You should use .test() to test the regex.",
- "testString": "assert(code.match(/myRegex.test\\(\\s*myString\\s*\\)/), 'You should use .test() to test the regex.');"
+ "text": "你应该使用 .test() 方法来检测正则表达式。",
+ "testString": "assert(code.match(/myRegex.test\\(\\s*myString\\s*\\)/), '你应该使用 .test() 方法来检测正则表达式。');"
},
{
- "text": "Your result should return true.",
- "testString": "assert(result === true, 'Your result should return true.');"
+ "text": "你的返回结果应该为 true。",
+ "testString": "assert(result === true, '你的返回结果应该为 true。');"
}
],
"solutions": [],
@@ -37,7 +37,7 @@
"contents": [
"let myString = \"Hello, World!\";",
"let myRegex = /Hello/;",
- "let result = myRegex; // Change this line"
+ "let result = myRegex; // 修改这一行"
],
"head": [],
"tail": []
@@ -48,26 +48,26 @@
"id": "587d7db3367417b2b2512b8f",
"title": "Match Literal Strings",
"description": [
- "In the last challenge, you searched for the word \"Hello\" using the regular expression /Hello/. That regex searched for a literal match of the string \"Hello\". Here's another example searching for a literal match of the string \"Kevin\":",
+ "在上一个挑战中,你使用正则表达式 /Hello/ 搜索到了字符串 \"Hello\"。那个正则表达式在字符串中搜寻 \"Hello\" 的文字匹配。下面是另一个在字符串中搜寻 \"Kevin\" 的示例:",
"let testStr = \"Hello, my name is Kevin.\";", - "Any other forms of
let testRegex = /Kevin/;
testRegex.test(testStr);
// Returns true
\"Kevin\" will not match. For example, the regex /Kevin/ will not match \"kevin\" or \"KEVIN\".",
+ "任何其他形式的 \"Kevin\" 都不会被匹配。例如,正则表达式 /Kevin/ 不会匹配 \"kevin\" 或者 \"KEVIN\"。",
"let wrongRegex = /kevin/;", - "A future challenge will show how to match those other forms as well.", + "后续的挑战将为你展示如何匹配其他形式的字符串。", "
wrongRegex.test(testStr);
// Returns false
waldoRegex to find \"Waldo\" in the string waldoIsHiding with a literal match."
+ "完成正则表达式 waldoRegex,在字符串 waldoIsHiding 中匹配到文本 \"Waldo\"。"
],
"tests": [
{
- "text": "Your regex waldoRegex should find \"Waldo\"",
- "testString": "assert(waldoRegex.test(waldoIsHiding), 'Your regex waldoRegex should find \"Waldo\"');"
+ "text": "你的正则表达式 waldoRegex 应该匹配到 \"Waldo\"。",
+ "testString": "assert(waldoRegex.test(waldoIsHiding), '你的正则表达式 waldoRegex 应该匹配到 \"Waldo\"。');"
},
{
- "text": "Your regex waldoRegex should not search for anything else.",
- "testString": "assert(!waldoRegex.test('Somewhere is hiding in this text.'), 'Your regex waldoRegex should not search for anything else.');"
+ "text": "你的正则表达式 waldoRegex 不应该搜寻其他的任何内容。",
+ "testString": "assert(!waldoRegex.test('Somewhere is hiding in this text.'), '你的正则表达式 waldoRegex 不应该搜寻其他的任何内容。');"
},
{
- "text": "You should perform a literal string match with your regex.",
- "testString": "assert(!/\\/.*\\/i/.test(code), 'You should perform a literal string match with your regex.');"
+ "text": "你应该使用你的正则表达式执行文字字符串匹配。",
+ "testString": "assert(!/\\/.*\\/i/.test(code), '你应该使用你的正则表达式执行文字字符串匹配。');"
}
],
"solutions": [],
@@ -81,7 +81,7 @@
"name": "index",
"contents": [
"let waldoIsHiding = \"Somewhere Waldo is hiding in this text.\";",
- "let waldoRegex = /search/; // Change this line",
+ "let waldoRegex = /search/; // 修改这一行",
"let result = waldoRegex.test(waldoIsHiding);"
],
"head": [],
@@ -93,41 +93,41 @@
"id": "587d7db4367417b2b2512b90",
"title": "Match a Literal String with Different Possibilities",
"description": [
- "Using regexes like /coding/, you can look for the pattern \"coding\" in another string.",
- "This is powerful to search single strings, but it's limited to only one pattern. You can search for multiple patterns using the alternation or OR operator: |.",
- "This operator matches patterns either before or after it. For example, if you wanted to match \"yes\" or \"no\", the regex you want is /yes|no/.",
- "You can also search for more than just two patterns. You can do this by adding more patterns with more OR operators separating them, like /yes|no|maybe/.",
+ "使用正则表达式 /coding/,你可以在其他字符串中查找 \"coding\"。",
+ "这对于搜寻单个字符串非常有用,但仅限于一种匹配模式。你可以使用 | 操作符来匹配多个规则。",
+ "此操作符匹配在它之前或之后的匹配模式。例如,如果你想匹配 \"yes\" 或 \"no\",你需要的正则表达式是 /yes|no/。",
+ "你还可以搜寻不止两个匹配模式。你可以通过添加更多的匹配模式来实现这一功能,这些匹配模式将包含更多的 | 操作符来分隔它们,比如 /yes|no|maybe/。",
"petRegex to match the pets \"dog\", \"cat\", \"bird\", or \"fish\"."
+ "完成正则表达式 petRegex 以匹配 \"dog\"、\"cat\"、\"bird\" 或者 \"fish\"。"
],
"tests": [
{
- "text": "Your regex petRegex should return true for the string \"John has a pet dog.\"",
- "testString": "assert(petRegex.test('John has a pet dog.'), 'Your regex petRegex should return true for the string \"John has a pet dog.\"');"
+ "text": "对于字符串 \"John has a pet dog.\",你的正则表达式 petRegex 的 test 方法应该返回 true。",
+ "testString": "assert(petRegex.test('John has a pet dog.'), '对于字符串 \"John has a pet dog.\",你的正则表达式 petRegex 的 test 方法应该返回 true。');"
},
{
- "text": "Your regex petRegex should return false for the string \"Emma has a pet rock.\"",
- "testString": "assert(!petRegex.test('Emma has a pet rock.'), 'Your regex petRegex should return false for the string \"Emma has a pet rock.\"');"
+ "text": "对于字符串 \"Emma has a pet rock.\",你的正则表达式 petRegex 的 test 方法应该返回 false。",
+ "testString": "assert(!petRegex.test('Emma has a pet rock.'), '对于字符串 \"Emma has a pet rock.\",你的正则表达式 petRegex 的 test 方法应该返回 false。');"
},
{
- "text": "Your regex petRegex should return true for the string \"Emma has a pet bird.\"",
- "testString": "assert(petRegex.test('Emma has a pet bird.'), 'Your regex petRegex should return true for the string \"Emma has a pet bird.\"');"
+ "text": "对于字符串 \"Emma has a pet bird.\",你的正则表达式 petRegex 的 test 方法应该返回 true。",
+ "testString": "assert(petRegex.test('Emma has a pet bird.'), '对于字符串 \"Emma has a pet bird.\",你的正则表达式 petRegex 的 test 方法应该返回 true。');"
},
{
- "text": "Your regex petRegex should return true for the string \"Liz has a pet cat.\"",
- "testString": "assert(petRegex.test('Liz has a pet cat.'), 'Your regex petRegex should return true for the string \"Liz has a pet cat.\"');"
+ "text": "对于字符串 \"Liz has a pet cat.\",你的正则表达式 petRegex 的 test 方法应该返回 true。",
+ "testString": "assert(petRegex.test('Liz has a pet cat.'), '对于字符串 \"Liz has a pet cat.\",你的正则表达式 petRegex 的 test 方法应该返回 true。');"
},
{
- "text": "Your regex petRegex should return false for the string \"Kara has a pet dolphin.\"",
- "testString": "assert(!petRegex.test('Kara has a pet dolphin.'), 'Your regex petRegex should return false for the string \"Kara has a pet dolphin.\"');"
+ "text": "对于字符串 \"Kara has a pet dolphin.\",你的正则表达式 petRegex 的 test 方法应该返回 false。",
+ "testString": "assert(!petRegex.test('Kara has a pet dolphin.'), '对于字符串 \"Kara has a pet dolphin.\",你的正则表达式 petRegex 的 test 方法应该返回 false。');"
},
{
- "text": "Your regex petRegex should return true for the string \"Alice has a pet fish.\"",
- "testString": "assert(petRegex.test('Alice has a pet fish.'), 'Your regex petRegex should return true for the string \"Alice has a pet fish.\"');"
+ "text": "对于字符串 \"Alice has a pet fish.\",你的正则表达式 petRegex 的 test 方法应该返回 true。",
+ "testString": "assert(petRegex.test('Alice has a pet fish.'), '对于字符串 \"Alice has a pet fish.\",你的正则表达式 petRegex 的 test 方法应该返回 true。');"
},
{
- "text": "Your regex petRegex should return false for the string \"Jimmy has a pet computer.\"",
- "testString": "assert(!petRegex.test('Jimmy has a pet computer.'), 'Your regex petRegex should return false for the string \"Jimmy has a pet computer.\"');"
+ "text": "对于字符串 \"Jimmy has a pet computer.\",你的正则表达式 petRegex 的 test 方法应该返回 false。",
+ "testString": "assert(!petRegex.test('Jimmy has a pet computer.'), '对于字符串 \"Jimmy has a pet computer.\",你的正则表达式 petRegex 的 test 方法应该返回 false。');"
}
],
"solutions": [],
@@ -141,7 +141,7 @@
"name": "index",
"contents": [
"let petString = \"James has a pet cat.\";",
- "let petRegex = /change/; // Change this line",
+ "let petRegex = /change/; // 修改这一行",
"let result = petRegex.test(petString);"
],
"head": [],
@@ -153,52 +153,52 @@
"id": "587d7db4367417b2b2512b91",
"title": "Ignore Case While Matching",
"description": [
- "Up until now, you've looked at regexes to do literal matches of strings. But sometimes, you might want to also match case differences.",
- "Case (or sometimes letter case) is the difference between uppercase letters and lowercase letters. Examples of uppercase are \"A\", \"B\", and \"C\". Examples of lowercase are \"a\", \"b\", and \"c\".",
- "You can match both cases using what is called a flag. There are other flags but here you'll focus on the flag that ignores case - the i flag. You can use it by appending it to the regex. An example of using this flag is /ignorecase/i. This regex can match the strings \"ignorecase\", \"igNoreCase\", and \"IgnoreCase\".",
+ "到目前为止,你已经查看了利用正则表达式来执行字符串的文字匹配。但是有时候,你可能也想匹配不同的英文字母大小写。",
+ "大小写(或者字母大小写)是大写字母和小写字母的区别。大写字母的例子有 \"A\"、\"B\" 和 \"C\"。小写字母的例子有 \"a\"、\"b\" 和 \"c\"。",
+ "你可以使用所谓的标志来匹配这两种情况。有许多其他标志,不过这里主要关注忽略大小写的标志 - i 标志。你可以通过将它附加到正则表达式之后来使用它。这里给出使用该标志的一个实例 /ignorecase/i。这个字符串可以匹配字符串 \"ignorecase\"、\"igNoreCase\" 和 \"IgnoreCase\"。",
"fccRegex to match \"freeCodeCamp\", no matter its case. Your regex should not match any abbreviations or variations with spaces."
+ "编写正则表达式 fccRegex 以匹配 \"freeCodeCamp\",忽略大小写。你的正则表达式不应与任何缩写或带有空格的变体匹配。"
],
"tests": [
{
- "text": "Your regex should match freeCodeCamp",
- "testString": "assert(fccRegex.test('freeCodeCamp'), 'Your regex should match freeCodeCamp');"
+ "text": "你的正则表达式应该匹配 freeCodeCamp。",
+ "testString": "assert(fccRegex.test('freeCodeCamp'), '你的正则表达式应该匹配 freeCodeCamp。');"
},
{
- "text": "Your regex should match FreeCodeCamp",
- "testString": "assert(fccRegex.test('FreeCodeCamp'), 'Your regex should match FreeCodeCamp');"
+ "text": "你的正则表达式应该匹配 FreeCodeCamp。",
+ "testString": "assert(fccRegex.test('FreeCodeCamp'), '你的正则表达式应该匹配 FreeCodeCamp。');"
},
{
- "text": "Your regex should match FreecodeCamp",
- "testString": "assert(fccRegex.test('FreecodeCamp'), 'Your regex should match FreecodeCamp');"
+ "text": "你的正则表达式应该匹配 FreecodeCamp。",
+ "testString": "assert(fccRegex.test('FreecodeCamp'), '你的正则表达式应该匹配 FreecodeCamp。');"
},
{
- "text": "Your regex should match FreeCodecamp",
- "testString": "assert(fccRegex.test('FreeCodecamp'), 'Your regex should match FreeCodecamp');"
+ "text": "你的正则表达式应该匹配 FreeCodecamp。",
+ "testString": "assert(fccRegex.test('FreeCodecamp'), '你的正则表达式应该匹配 FreeCodecamp。');"
},
{
- "text": "Your regex should not match Free Code Camp",
- "testString": "assert(!fccRegex.test('Free Code Camp'), 'Your regex should not match Free Code Camp');"
+ "text": "你的正则表达式不应该匹配 Free Code Camp。",
+ "testString": "assert(!fccRegex.test('Free Code Camp'), '你的正则表达式不应该匹配 Free Code Camp。');"
},
{
- "text": "Your regex should match FreeCOdeCamp",
- "testString": "assert(fccRegex.test('FreeCOdeCamp'), 'Your regex should match FreeCOdeCamp');"
+ "text": "Your regex should match FreeCOdeCamp。",
+ "testString": "assert(fccRegex.test('FreeCOdeCamp'), 'Your regex should match FreeCOdeCamp。');"
},
{
- "text": "Your regex should not match FCC",
- "testString": "assert(!fccRegex.test('FCC'), 'Your regex should not match FCC');"
+ "text": "你的正则表达式不应该匹配 FCC。",
+ "testString": "assert(!fccRegex.test('FCC'), '你的正则表达式不应该匹配 FCC。');"
},
{
- "text": "Your regex should match FrEeCoDeCamp",
- "testString": "assert(fccRegex.test('FrEeCoDeCamp'), 'Your regex should match FrEeCoDeCamp');"
+ "text": "你的正则表达式应该匹配 FrEeCoDeCamp。",
+ "testString": "assert(fccRegex.test('FrEeCoDeCamp'), '你的正则表达式应该匹配 FrEeCoDeCamp。');"
},
{
- "text": "Your regex should match FrEeCodECamp",
- "testString": "assert(fccRegex.test('FrEeCodECamp'), 'Your regex should match FrEeCodECamp');"
+ "text": "你的正则表达式应该匹配 FrEeCodECamp。",
+ "testString": "assert(fccRegex.test('FrEeCodECamp'), '你的正则表达式应该匹配 FrEeCodECamp。');"
},
{
- "text": "Your regex should match FReeCodeCAmp",
- "testString": "assert(fccRegex.test('FReeCodeCAmp'), 'Your regex should match FReeCodeCAmp');"
+ "text": "你的正则表达式应该匹配 FReeCodeCAmp。",
+ "testString": "assert(fccRegex.test('FReeCodeCAmp'), '你的正则表达式应该匹配 FReeCodeCAmp。');"
}
],
"solutions": [],
@@ -212,7 +212,7 @@
"name": "index",
"contents": [
"let myString = \"freeCodeCamp\";",
- "let fccRegex = /change/; // Change this line",
+ "let fccRegex = /change/; // 修改这一行",
"let result = fccRegex.test(myString);"
],
"head": [],
@@ -224,24 +224,24 @@
"id": "587d7db4367417b2b2512b92",
"title": "Extract Matches",
"description": [
- "So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the .match() method.",
- "To use the .match() method, apply the method on a string and pass in the regex inside the parentheses. Here's an example:",
+ "到目前为止,你只是检查了一个匹配模式是否存在于字符串中。你还可以使用 .match() 方法来提取你找到的实际匹配项。",
+ "要使用 .match() 方法,请将该方法应用到字符串上,并在括号内传入正则表达式。这里是一个案例:",
"\"Hello, World!\".match(/Hello/);", "
// Returns [\"Hello\"]
let ourStr = \"Regular expressions\";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns [\"expressions\"]
.match() method to extract the word coding."
+ "利用 .match() 方法提取单词 coding。"
],
"tests": [
{
- "text": "The result should have the word coding",
- "testString": "assert(result.join() === \"coding\", 'The result should have the word coding');"
+ "text": "结果应该包含单词 coding。",
+ "testString": "assert(result.join() === \"coding\", '结果应该包含单词 coding。');"
},
{
- "text": "Your regex codingRegex should search for coding",
- "testString": "assert(codingRegex.source === \"coding\", 'Your regex codingRegex should search for coding');"
+ "text": "你的正则表达式 codingRegex 应该搜寻 coding。",
+ "testString": "assert(codingRegex.source === \"coding\", '你的正则表达式 codingRegex 应该搜寻 coding。');"
},
{
- "text": "You should use the .match() method.",
- "testString": "assert(code.match(/\\.match\\(.*\\)/), 'You should use the .match() method.');"
+ "text": "你应该使用 .match() 方法。",
+ "testString": "assert(code.match(/\\.match\\(.*\\)/), '你应该使用 .match() 方法。');"
}
],
"solutions": [],
@@ -255,8 +255,8 @@
"name": "index",
"contents": [
"let extractStr = \"Extract the word 'coding' from this string.\";",
- "let codingRegex = /change/; // Change this line",
- "let result = extractStr; // Change this line"
+ "let codingRegex = /change/; // 修改这一行",
+ "let result = extractStr; // 修改这一行"
],
"head": [],
"tail": []
@@ -267,30 +267,30 @@
"id": "587d7db4367417b2b2512b93",
"title": "Find More Than the First Match",
"description": [
- "So far, you have only been able to extract or search a pattern once.",
+ "到目前为止,你只能提取或搜寻一次匹配模式。",
"let testStr = \"Repeat, Repeat, Repeat\";", - "To search or extract a pattern more than once, you can use the
let ourRegex = /Repeat/;
testStr.match(ourRegex);
// Returns [\"Repeat\"]
g flag.",
+ "若要多次搜寻或提取匹配模式,你可以使用 g 标志。",
"let repeatRegex = /Repeat/g;", "
testStr.match(repeatRegex);
// Returns [\"Repeat\", \"Repeat\", \"Repeat\"]
starRegex, find and extract both \"Twinkle\" words from the string twinkleStar.",
- "Note/search/gi"
+ "使用正则表达式 starRegex,从字符串 twinkleStar 中匹配到所有的 \"Twinkle\" 单词并提取出来。",
+ "注意/search/gi。"
],
"tests": [
{
- "text": "Your regex starRegex should use the global flag g",
- "testString": "assert(starRegex.flags.match(/g/).length == 1, 'Your regex starRegex should use the global flag g');"
+ "text": "你的正则表达式 starRegex 应该使用全局标志 g。",
+ "testString": "assert(starRegex.flags.match(/g/).length == 1, '你的正则表达式 starRegex 应该使用全局标志 g。');"
},
{
- "text": "Your regex starRegex should use the case insensitive flag i",
- "testString": "assert(starRegex.flags.match(/i/).length == 1, 'Your regex starRegex should use the case insensitive flag i');"
+ "text": "你的正则表达式 starRegex 应该使用忽略大小写标志 i。",
+ "testString": "assert(starRegex.flags.match(/i/).length == 1, '你的正则表达式 starRegex 应该使用忽略大小写标志 i。');"
},
{
- "text": "Your match should match both occurrences of the word \"Twinkle\"",
- "testString": "assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), 'Your match should match both occurrences of the word \"Twinkle\"');"
+ "text": "你的匹配应该匹配单词 \"Twinkle\" 的两个匹配项。",
+ "testString": "assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), '你的匹配应该匹配单词 \"Twinkle\" 的两个匹配项。');"
},
{
- "text": "Your match result should have two elements in it.",
- "testString": "assert(result.length == 2, 'Your match result should have two elements in it.');"
+ "text": "你的匹配结果应该包含两个元素。",
+ "testString": "assert(result.length == 2, '你的匹配结果应该包含两个元素。');"
}
],
"solutions": [],
@@ -304,8 +304,8 @@
"name": "index",
"contents": [
"let twinkleStar = \"Twinkle, twinkle, little star\";",
- "let starRegex = /change/; // Change this line",
- "let result = twinkleStar; // Change this line"
+ "let starRegex = /change/; // 修改这一行",
+ "let result = twinkleStar; // 修改这一行"
],
"head": [],
"tail": []
@@ -316,52 +316,52 @@
"id": "587d7db5367417b2b2512b94",
"title": "Match Anything with Wildcard Period",
"description": [
- "Sometimes you won't (or don't need to) know the exact characters in your patterns. Thinking of all words that match, say, a misspelling would take a long time. Luckily, you can save time using the wildcard character: .",
- "The wildcard character . will match any one character. The wildcard is also called dot and period. You can use the wildcard character just like any other character in the regex. For example, if you wanted to match \"hug\", \"huh\", \"hut\", and \"hum\", you can use the regex /hu./ to match all four words.",
+ "有时你不会(或不需要)知道匹配模式中的确切字符。比如,考虑到要匹配到所有的单词,有一个拼写错误就会耗费很长时间。幸运的是,你可以使用通配符 . 来节约你的时间。",
+ "通配符 . 将匹配任何一个字符。通配符也被称为 点 和 句号。你可以像使用正则表达式中任何其他字符一样使用通配符。例如,如果你想匹配 \"hug\"、\"huh\"、\"hut\" 和 \"hum\",你可以使用正则表达式 /hu./ 匹配所有的四个单词。",
"let humStr = \"I'll hum a song\";", "
let hugStr = \"Bear hug\";
let huRegex = /hu./;
humStr.match(huRegex); // Returns [\"hum\"]
hugStr.match(huRegex); // Returns [\"hug\"]
unRegex so that it matches the strings \"run\", \"sun\", \"fun\", \"pun\", \"nun\", and \"bun\". Your regex should use the wildcard character."
+ "完成正则表达式 unRegex 以匹配字符串 \"run\"、\"sun\"、\"fun\"、\"pun\"、\"nun\" 和 \"bun\"。你的正则表达式中应该使用通配符。"
],
"tests": [
{
- "text": "You should use the .test() method.",
- "testString": "assert(code.match(/\\.test\\(.*\\)/), 'You should use the .test() method.');"
+ "text": "你应该使用 .test() 方法。",
+ "testString": "assert(code.match(/\\.test\\(.*\\)/), '你应该使用 .test() 方法。');"
},
{
- "text": "You should use the wildcard character in your regex unRegex",
- "testString": "assert(/\\./.test(unRegex.source), 'You should use the wildcard character in your regex unRegex');"
+ "text": "你应该在你的正则表达式 unRegex 中使用通配符。",
+ "testString": "assert(/\\./.test(unRegex.source), '你应该在你的正则表达式 unRegex 中使用通配符。');"
},
{
- "text": "Your regex unRegex should match \"run\" in \"Let us go on a run.\"",
- "testString": "assert(unRegex.test(\"Let us go on a run.\"), 'Your regex unRegex should match \"run\" in \"Let us go on a run.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"Let us go on a run.\" 中匹配到 \"run\" 单词。",
+ "testString": "assert(unRegex.test(\"Let us go on a run.\"), '你的正则表达式 unRegex 应该在字符串 \"Let us go on a run.\" 中匹配到 \"run\" 单词。');"
},
{
- "text": "Your regex unRegex should match \"sun\" in \"The sun is out today.\"",
- "testString": "assert(unRegex.test(\"The sun is out today.\"), 'Your regex unRegex should match \"sun\" in \"The sun is out today.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"The sun is out today.\" 中匹配到 \"sun\" 单词。",
+ "testString": "assert(unRegex.test(\"The sun is out today.\"), '你的正则表达式 unRegex 应该在字符串 \"The sun is out today.\" 中匹配到 \"sun\" 单词。');"
},
{
- "text": "Your regex unRegex should match \"fun\" in \"Coding is a lot of fun.\"",
- "testString": "assert(unRegex.test(\"Coding is a lot of fun.\"), 'Your regex unRegex should match \"fun\" in \"Coding is a lot of fun.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"Coding is a lot of fun.\" 中匹配到 \"fun\" 单词。",
+ "testString": "assert(unRegex.test(\"Coding is a lot of fun.\"), '你的正则表达式 unRegex 应该在字符串 \"Coding is a lot of fun.\" 中匹配到 \"fun\" 单词。');"
},
{
- "text": "Your regex unRegex should match \"pun\" in \"Seven days without a pun makes one weak.\"",
- "testString": "assert(unRegex.test(\"Seven days without a pun makes one weak.\"), 'Your regex unRegex should match \"pun\" in \"Seven days without a pun makes one weak.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"Seven days without a pun makes one weak.\" 中匹配到 \"pun\" 单词。",
+ "testString": "assert(unRegex.test(\"Seven days without a pun makes one weak.\"), '你的正则表达式 unRegex 应该在字符串 \"Seven days without a pun makes one weak.\" 中匹配到 \"pun\" 单词。');"
},
{
- "text": "Your regex unRegex should match \"nun\" in \"One takes a vow to be a nun.\"",
- "testString": "assert(unRegex.test(\"One takes a vow to be a nun.\"), 'Your regex unRegex should match \"nun\" in \"One takes a vow to be a nun.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"One takes a vow to be a nun.\" 中匹配到 \"nun\" 单词。",
+ "testString": "assert(unRegex.test(\"One takes a vow to be a nun.\"), '你的正则表达式 unRegex 应该在字符串 \"One takes a vow to be a nun.\" 中匹配到 \"nun\" 单词。');"
},
{
- "text": "Your regex unRegex should match \"bun\" in \"She got fired from the hot dog stand for putting her hair in a bun.\"",
- "testString": "assert(unRegex.test(\"She got fired from the hot dog stand for putting her hair in a bun.\"), 'Your regex unRegex should match \"bun\" in \"She got fired from the hot dog stand for putting her hair in a bun.\"');"
+ "text": "你的正则表达式 unRegex 应该在字符串 \"She got fired from the hot dog stand for putting her hair in a bun.\" 中匹配到 \"bun\" 单词。",
+ "testString": "assert(unRegex.test(\"She got fired from the hot dog stand for putting her hair in a bun.\"), '你的正则表达式 unRegex 应该在字符串 \"She got fired from the hot dog stand for putting her hair in a bun.\" 中匹配到 \"bun\" 单词。');"
},
{
- "text": "Your regex unRegex should not match \"There is a bug in my code.\"",
- "testString": "assert(!unRegex.test(\"There is a bug in my code.\"), 'Your regex unRegex should not match \"There is a bug in my code.\"');"
+ "text": "你的正则表达式 unRegex 不应该匹配 \"There is a bug in my code.\"。",
+ "testString": "assert(!unRegex.test(\"There is a bug in my code.\"), '你的正则表达式 unRegex 不应该匹配 \"There is a bug in my code.\"。');"
},
{
- "text": "Your regex unRegex should not match \"Catch me if you can.\"",
- "testString": "assert(!unRegex.test(\"Can me if you can.\"), 'Your regex unRegex should not match \"Catch me if you can.\"');"
+ "text": "你的正则表达式 unRegex 不应该匹配 \"Catch me if you can.\"。",
+ "testString": "assert(!unRegex.test(\"Can me if you can.\"), '你的正则表达式 unRegex 不应该匹配 \"Catch me if you can.\"。');"
}
],
"solutions": [],
@@ -375,7 +375,7 @@
"name": "index",
"contents": [
"let exampleStr = \"Let's have fun with regular expressions!\";",
- "let unRegex = /change/; // Change this line",
+ "let unRegex = /change/; // 修改这一行",
"let result = unRegex.test(exampleStr);"
],
"head": [],
@@ -387,34 +387,34 @@
"id": "587d7db5367417b2b2512b95",
"title": "Match Single Character with Multiple Possibilities",
"description": [
- "You learned how to match literal patterns (/literal/) and wildcard character (/./). Those are the extremes of regular expressions, where one finds exact matches and the other matches everything. There are options that are a balance between the two extremes.",
- "You can search for a literal pattern with some flexibility with character classes. Character classes allow you to define a group of characters you wish to match by placing them inside square ([ and ]) brackets.",
- "For example, you want to match \"bag\", \"big\", and \"bug\" but not \"bog\". You can create the regex /b[aiu]g/ to do this. The [aiu] is the character class that will only match the characters \"a\", \"i\", or \"u\".",
+ "你学习了如何匹配文字匹配模式(/literal/)和通配符(/./)。这是正则表达式的两种极端情况,一种是精确匹配,而另一种则是匹配所有。在这两种极端情况之间有一个平衡选项。",
+ "你可以使用字符集搜寻具有一定灵活性的文字匹配模式。字符集允许你通过把它们放在方括号([ 和 ])之间的方式来定义一组你需要匹配的字符串。",
+ "例如,你想要匹配 \"bag\"、\"big\" 和 \"bug\",但是不想匹配 \"bog\"。你可以创建正则表达式 /b[aiu]g/ 来执行此操作。[aiu] 是只匹配字符 \"a\"、\"i\" 或者 \"u\" 的字符集。",
"let bigStr = \"big\";", "
let bagStr = \"bag\";
let bugStr = \"bug\";
let bogStr = \"bog\";
let bgRegex = /b[aiu]g/;
bigStr.match(bgRegex); // Returns [\"big\"]
bagStr.match(bgRegex); // Returns [\"bag\"]
bugStr.match(bgRegex); // Returns [\"bug\"]
bogStr.match(bgRegex); // Returns null
a, e, i, o, u) in your regex vowelRegex to find all the vowels in the string quoteSample.",
- "Notea、e、i、o、u)在你的正则表达式 vowelRegex 中匹配到字符串 quoteSample 中的所有元音。",
+ "注意vowelRegex should use a character class.",
- "testString": "assert(/\\[.*\\]/.test(vowelRegex.source), 'Your regex vowelRegex should use a character class.');"
+ "text": "你的正则表达式 vowelRegex 应该使用字符集。",
+ "testString": "assert(/\\[.*\\]/.test(vowelRegex.source), '你的正则表达式 vowelRegex 应该使用字符集。');"
},
{
- "text": "Your regex vowelRegex should use the global flag.",
- "testString": "assert(vowelRegex.flags.match(/g/).length == 1, 'Your regex vowelRegex should use the global flag.');"
+ "text": "你的正则表达式 vowelRegex 应该使用全局标志。",
+ "testString": "assert(vowelRegex.flags.match(/g/).length == 1, '你的正则表达式 vowelRegex 应该使用全局标志。');"
},
{
- "text": "Your regex vowelRegex should use the case insensitive flag.",
- "testString": "assert(vowelRegex.flags.match(/i/).length == 1, 'Your regex vowelRegex should use the case insensitive flag.');"
+ "text": "你的正则表达式 vowelRegex 应该使用忽略大小写标志。",
+ "testString": "assert(vowelRegex.flags.match(/i/).length == 1, '你的正则表达式 vowelRegex 应该使用忽略大小写标志。');"
},
{
- "text": "Your regex should not match any consonants.",
- "testString": "assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()), 'Your regex should not match any consonants.');"
+ "text": "你的正则表达式不应该匹配任何辅音。",
+ "testString": "assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()), '你的正则表达式不应该匹配任何辅音。');"
}
],
"solutions": [],
@@ -428,8 +428,8 @@
"name": "index",
"contents": [
"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"
+ "let vowelRegex = /change/; // 修改这一行",
+ "let result = vowelRegex; // 修改这一行"
],
"head": [],
"tail": []
@@ -440,26 +440,26 @@
"id": "587d7db5367417b2b2512b96",
"title": "Match Letters of the Alphabet",
"description": [
- "You saw how you can use character sets to specify a group of characters to match, but that's a lot of typing when you need to match a large range of characters (for example, every letter in the alphabet). Fortunately, there is a built-in feature that makes this short and simple.",
- "Inside a character set, you can define a range of characters to match using a hyphen character: -.",
- "For example, to match lowercase letters a through e you would use [a-e].",
+ "你了解了如何使用字符集来指定要匹配的一组字符串,但是当你需要匹配大量字符(例如,字母表中的每个字母)时。幸运的是,有一个内置的特性使这个功能变得简短。",
+ "在字符集中,你可以使用连字符(-)来定义要匹配的字符范围。",
+ "例如,要匹配小写字母 a 到 e,你可以使用 [a-e]。",
"let catStr = \"cat\";", "
let batStr = \"bat\";
let matStr = \"mat\";
let bgRegex = /[a-e]at/;
catStr.match(bgRegex); // Returns [\"cat\"]
batStr.match(bgRegex); // Returns [\"bat\"]
matStr.match(bgRegex); // Returns null
quoteSample.",
- "NotequoteSample 中的所有字母。",
+ "注意alphabetRegex should match 35 items.",
- "testString": "assert(result.length == 35, 'Your regex alphabetRegex should match 35 items.');"
+ "text": "你的正则表达式 alphabetRegex 应该匹配 35 项。",
+ "testString": "assert(result.length == 35, '你的正则表达式 alphabetRegex 应该匹配 35 项。');"
},
{
- "text": "Your regex alphabetRegex should use the global flag.",
- "testString": "assert(alphabetRegex.flags.match(/g/).length == 1, 'Your regex alphabetRegex should use the global flag.');"
+ "text": "你的正则表达式 alphabetRegex 应该使用全局标志。",
+ "testString": "assert(alphabetRegex.flags.match(/g/).length == 1, '你的正则表达式 alphabetRegex 应该使用全局标志。');"
},
{
- "text": "Your regex alphabetRegex should use the case insensitive flag.",
- "testString": "assert(alphabetRegex.flags.match(/i/).length == 1, 'Your regex alphabetRegex should use the case insensitive flag.');"
+ "text": "你的正则表达式 alphabetRegex 应该使用忽略大小写标志。",
+ "testString": "assert(alphabetRegex.flags.match(/i/).length == 1, '你的正则表达式 alphabetRegex 应该使用忽略大小写标志。');"
}
],
"solutions": [],
@@ -473,8 +473,8 @@
"name": "index",
"contents": [
"let quoteSample = \"The quick brown fox jumps over the lazy dog.\";",
- "let alphabetRegex = /change/; // Change this line",
- "let result = alphabetRegex; // Change this line"
+ "let alphabetRegex = /change/; // 修改这一行",
+ "let result = alphabetRegex; // 修改这一行"
],
"head": [],
"tail": []
@@ -485,25 +485,25 @@
"id": "587d7db5367417b2b2512b97",
"title": "Match Numbers and Letters of the Alphabet",
"description": [
- "Using the hyphen (-) to match a range of characters is not limited to letters. It also works to match a range of numbers.",
- "For example, /[0-5]/ matches any number between 0 and 5, including the 0 and 5.",
- "Also, it is possible to combine a range of letters and numbers in a single character set.",
+ "使用连字符(-)匹配字符范围并不仅限于字母。它还可以匹配一系列数字。",
+ "例如,/[0-5]/ 匹配 0 和 5 之间的任意数字,包含 0 和 5。",
+ "此外,还可以在单个字符集中组合一系列字母和数字。",
"let jennyStr = \"Jenny8675309\";", "
let myRegex = /[a-z0-9]/ig;
// matches all letters and numbers in jennyStr
jennyStr.match(myRegex);
h and s, and a range of numbers between 2 and 6. Remember to include the appropriate flags in the regex."
+ "创建一个正则表达式,使其可以匹配 h 和 s 之间的一系列字母,以及 2 and 6 之间的一系列数字。请记住在正则表达式中包含恰当的标志。"
],
"tests": [
{
- "text": "Your regex myRegex should match 17 items.",
- "testString": "assert(result.length == 17, 'Your regex myRegex should match 17 items.');"
+ "text": "你的正则表达式 myRegex 应该匹配 17 项。",
+ "testString": "assert(result.length == 17, '你的正则表达式 myRegex 应该匹配 17 项。');"
},
{
- "text": "Your regex myRegex should use the global flag.",
- "testString": "assert(myRegex.flags.match(/g/).length == 1, 'Your regex myRegex should use the global flag.');"
+ "text": "你的正则表达式 myRegex 应该使用全局标志。",
+ "testString": "assert(myRegex.flags.match(/g/).length == 1, '你的正则表达式 myRegex 应该使用全局标志。');"
},
{
- "text": "Your regex myRegex should use the case insensitive flag.",
- "testString": "assert(myRegex.flags.match(/i/).length == 1, 'Your regex myRegex should use the case insensitive flag.');"
+ "text": "你的正则表达式 myRegex 应该使用忽略大小写标志。",
+ "testString": "assert(myRegex.flags.match(/i/).length == 1, '你的正则表达式 myRegex 应该使用忽略大小写标志。');"
}
],
"solutions": [],
@@ -517,8 +517,8 @@
"name": "index",
"contents": [
"let quoteSample = \"Blueberry 3.141592653s are delicious.\";",
- "let myRegex = /change/; // Change this line",
- "let result = myRegex; // Change this line"
+ "let myRegex = /change/; // 修改这一行",
+ "let result = myRegex; // 修改这一行"
],
"head": [],
"tail": []
@@ -529,24 +529,24 @@
"id": "587d7db6367417b2b2512b98",
"title": "Match Single Characters Not Specified",
"description": [
- "So far, you have created a set of characters that you want to match, but you could also create a set of characters that you do not want to match. These types of character sets are called negated character sets.",
- "To create a negated character set, you place a caret character (^) after the opening bracket and before the characters you do not want to match.",
- "For example, /[^aeiou]/gi matches all characters that are not a vowel. Note that characters like ., !, [, @, / and white space are matched - the negated vowel character set only excludes the vowel characters.",
+ "到目前为止,你已创建了一个你想要匹配的字符集合,但你也可以创建一个你不想匹配的字符集合。这些类型的字符集称为否定字符集。",
+ "要创建否定字符集,你需要在开始括号后面和不想匹配的字符前面放置插入字符(即 ^)。",
+ "例如,/[^aeiou]/gi 匹配所有非元音字符。注意,字符 .、!、[、@、/ 和空白字符也会被匹配,该否定字符集仅排除元音字符。",
"myRegex should match 9 items.",
- "testString": "assert(result.length == 9, 'Your regex myRegex should match 9 items.');"
+ "text": "你的正则表达式 myRegex 应该匹配 9 项。",
+ "testString": "assert(result.length == 9, '你的正则表达式 myRegex 应该匹配 9 项。');"
},
{
- "text": "Your regex myRegex should use the global flag.",
- "testString": "assert(myRegex.flags.match(/g/).length == 1, 'Your regex myRegex should use the global flag.');"
+ "text": "你的正则表达式 myRegex 应该使用全局标志。",
+ "testString": "assert(myRegex.flags.match(/g/).length == 1, '你的正则表达式 myRegex 应该使用全局标志。');"
},
{
- "text": "Your regex myRegex should use the case insensitive flag.",
- "testString": "assert(myRegex.flags.match(/i/).length == 1, 'Your regex myRegex should use the case insensitive flag.');"
+ "text": "你的正则表达式 myRegex 应该使用忽略大小写标志。",
+ "testString": "assert(myRegex.flags.match(/i/).length == 1, '你的正则表达式 myRegex 应该使用忽略大小写标志。');"
}
],
"solutions": [],
@@ -560,8 +560,8 @@
"name": "index",
"contents": [
"let quoteSample = \"3 blind mice.\";",
- "let myRegex = /change/; // Change this line",
- "let result = myRegex; // Change this line"
+ "let myRegex = /change/; // 修改这一行",
+ "let result = myRegex; // 修改这一行"
],
"head": [],
"tail": []
@@ -572,25 +572,25 @@
"id": "587d7db6367417b2b2512b99",
"title": "Match Characters that Occur One or More Times",
"description": [
- "Sometimes, you need to match a character (or group of characters) that appears one or more times in a row. This means it occurs at least once, and may be repeated.",
- "You can use the + character to check if that is the case. Remember, the character or pattern has to be present consecutively. That is, the character has to repeat one after the other.",
- "For example, /a+/g would find one match in \"abc\" and return [\"a\"]. Because of the +, it would also find a single match in \"aabc\" and return [\"aa\"].",
- "If it were instead checking the string \"abab\", it would find two matches and return [\"a\", \"a\"] because the a characters are not in a row - there is a b between them. Finally, since there is no \"a\" in the string \"bcd\", it wouldn't find a match.",
+ "有时,你需要匹配出现一次或者连续多次的的字符(或字符组)。这意味着它至少出现一次,并且可能重复出现。",
+ "你可以使用 + 符号来检查情况是否如此。记住,字符或匹配模式必须必须连续出现。也就是说,字符必须一个接一个的重复出现。",
+ "例如, /a+/g 会在 \"abc\" 中匹配到一个匹配项,并且返回 [\"a\"]。因为 + 的存在,它也会在 \"aabc\" 中匹配到一个匹配项,然后返回 [\"aa\"]。",
+ "如果它是检查字符串 \"abab\",它将匹配到两个匹配项并且返回 [\"a\", \"a\"],因为 a 字符不连续,在它们之间有一个 b 字符。最后,因为在字符串 \"bcd\" 中没有 \"a\",因此找不到匹配项。",
"s occurs one or more times in \"Mississippi\". Write a regex that uses the + sign."
+ "你希望在字符串 \"Mississippi\" 中匹配到出现一次或多次的字母 s 的匹配项。编写一个使用 + 符号的正则表达式。"
],
"tests": [
{
- "text": "Your regex myRegex should use the + sign to match one or more s characters.",
- "testString": "assert(/\\+/.test(myRegex.source), 'Your regex myRegex should use the + sign to match one or more s characters.');"
+ "text": "你的正则表达式 myRegex 应该使用 + 符号来匹配一个或多个 s 字符。",
+ "testString": "assert(/\\+/.test(myRegex.source), '你的正则表达式 myRegex 应该使用 + 符号来匹配一个或多个 s 字符。');"
},
{
- "text": "Your regex myRegex should match 2 items.",
- "testString": "assert(result.length == 2, 'Your regex myRegex should match 2 items.');"
+ "text": "你的正则表达式 myRegex 应该匹配两项。",
+ "testString": "assert(result.length == 2, '你的正则表达式 myRegex 应该匹配两项。');"
},
{
- "text": "The result variable should be an array with two matches of \"ss\"",
- "testString": "assert(result[0] == 'ss' && result[1] == 'ss', 'The result variable should be an array with two matches of \"ss\"');"
+ "text": "结果变量应该是一个包含两个 \"ss\" 匹配项的数组。",
+ "testString": "assert(result[0] == 'ss' && result[1] == 'ss', '结果变量应该是一个包含两个 \"ss\" 匹配项的数组。');"
}
],
"solutions": [],
@@ -604,7 +604,7 @@
"name": "index",
"contents": [
"let difficultSpelling = \"Mississippi\";",
- "let myRegex = /change/; // Change this line",
+ "let myRegex = /change/; // 修改这一行",
"let result = difficultSpelling.match(myRegex);"
],
"head": [],
@@ -616,32 +616,32 @@
"id": "587d7db6367417b2b2512b9a",
"title": "Match Characters that Occur Zero or More Times",
"description": [
- "The last challenge used the plus + sign to look for characters that occur one or more times. There's also an option that matches characters that occur zero or more times.",
- "The character to do this is the asterisk or star: *.",
+ "上一次的挑战中使用了加号 + 来查找出现一次或多次的字符。还有一个选项可以匹配出现零次或多次的字符。",
+ "执行该操作的字符是 asterisk 或 star:*。",
"let soccerWord = \"gooooooooal!\";", "
let gPhrase = \"gut feeling\";
let oPhrase = \"over the moon\";
let goRegex = /go*/;
soccerWord.match(goRegex); // Returns [\"goooooooo\"]
gPhrase.match(goRegex); // Returns [\"g\"]
oPhrase.match(goRegex); // Returns null
chewieRegex that uses the * character to match all the upper and lower\"a\" characters in chewieQuote. Your regex does not need flags, and it should not match any of the other quotes."
+ "创建一个正则表达式 chewieRegex,使用 * 符号在 chewieQuote 中匹配大小写的 \"a\" 字符。你的正则表达式不需要标志,也不应该匹配任何其他引号。"
],
"tests": [
{
- "text": "Your regex chewieRegex should use the * character to match zero or more a characters.",
- "testString": "assert(/\\*/.test(chewieRegex.source), 'Your regex chewieRegex should use the * character to match zero or more a characters.');"
+ "text": "你的正则表达式 chewieRegex 应该使用 * 符号匹配零个或多个 a 字符。",
+ "testString": "assert(/\\*/.test(chewieRegex.source), '你的正则表达式 chewieRegex 应该使用 * 符号匹配零个或多个 a 字符。');"
},
{
- "text": "Your regex chewieRegex should match 16 characters.",
- "testString": "assert(result[0].length === 16, 'Your regex chewieRegex should match 16 characters.');"
+ "text": "你的正则表达式 chewieRegex 应该匹配 16 个字符。",
+ "testString": "assert(result[0].length === 16, '你的正则表达式 chewieRegex 应该匹配 16 个字符。');"
},
{
- "text": "Your regex should match \"Aaaaaaaaaaaaaaaa\".",
- "testString": "assert(result[0] === 'Aaaaaaaaaaaaaaaa', 'Your regex should match \"Aaaaaaaaaaaaaaaa\".');"
+ "text": "你的正则表达式应该匹配 \"Aaaaaaaaaaaaaaaa\"。",
+ "testString": "assert(result[0] === 'Aaaaaaaaaaaaaaaa', '你的正则表达式应该匹配 \"Aaaaaaaaaaaaaaaa\"。');"
},
{
- "text": "Your regex should not match any characters in \"He made a fair move. Screaming about it can't help you.\"",
- "testString": "assert(!\"He made a fair move. Screaming about it can\\'t help you.\".match(chewieRegex), 'Your regex should not match any characters in \"He made a fair move. Screaming about it can't help you.\"');"
+ "text": "你的正则表达式在 \"He made a fair move. Screaming about it can't help you.\" 中不应该匹配任何字符。",
+ "testString": "assert(!\"He made a fair move. Screaming about it can\\'t help you.\".match(chewieRegex), '你的正则表达式在 \"He made a fair move. Screaming about it can't help you.\" 中不应该匹配任何字符。');"
},
{
- "text": "Your regex should not match any characters in \"Let him have it. It's not wise to upset a Wookiee.\"",
- "testString": "assert(!\"Let him have it. It\\'s not wise to upset a Wookiee.\".match(chewieRegex), 'Your regex should not match any characters in \"Let him have it. It's not wise to upset a Wookiee.\"');"
+ "text": "你的正则表达式在 \"Let him have it. It's not wise to upset a Wookiee.\" 中不应该匹配任何字符。",
+ "testString": "assert(!\"Let him have it. It\\'s not wise to upset a Wookiee.\".match(chewieRegex), '你的正则表达式在 \"Let him have it. It's not wise to upset a Wookiee.\" 中不应该匹配任何字符。');"
}
],
"solutions": [],
@@ -655,7 +655,7 @@
"name": "index",
"contents": [
"let chewieQuote = \"Aaaaaaaaaaaaaaaarrrgh!\";",
- "let chewieRegex = /change/; // Change this line",
+ "let chewieRegex = /change/; // 修改这一行",
"let result = chewieQuote.match(chewieRegex);"
],
"head": [],
@@ -667,17 +667,17 @@
"id": "587d7db6367417b2b2512b9b",
"title": "Find Characters with Lazy Matching",
"description": [
- "In regular expressions, a greedy match finds the longest possible part of a string that fits the regex pattern and returns it as a match. The alternative is called a lazy match, which finds the smallest possible part of the string that satisfies the regex pattern.",
- "You can apply the regex /t[a-z]*i/ to the string \"titanic\". This regex is basically a pattern that starts with t, ends with i, and has some letters in between.",
- "Regular expressions are by default greedy, so the match would return [\"titani\"]. It finds the largest sub-string possible to fit the pattern.",
- "However, you can use the ? character to change it to lazy matching. \"titanic\" matched against the adjusted regex of /t[a-z]*?i/ returns [\"ti\"].",
+ "在正则表达式中,贪婪匹配会匹配到符合正则表达式匹配模式的字符串的最长可能部分,并将其作为匹配项返回。另一种方案称为懒惰匹配,它会匹配到满足正则表达式的字符串的最小可能部分。",
+ "你可以将正则表达式 /t[a-z]*i/ 应用于字符串 \"titanic\"。这个正则表达式基本上是一个以 t 开始,以 i 结束,并且中间有一些字母的匹配模式。",
+ "正则表达式默认是贪婪匹配,因此匹配返回为 [\"titani\"]。它会匹配到适合该匹配模式的最大子字符串。",
+ "但是,你可以使用 ? 字符来将其变成懒惰匹配。调整后的正则表达式 /t[a-z]*?i/ 匹配字符串 \"titanic\" 返回 [\"ti\"]。",
"/<.*>/ to return the HTML tag <h1> and not the text \"<h1>Winter is coming</h1>\". Remember the wildcard . in a regular expression matches any character."
+ "修复正则表达式 /<.*>/ 返回HTML标签 <h1>,而不是文本 \"<h1>Winter is coming</h1>\"。请记住在正则表达式中使用通配符 . 来匹配任意字符。"
],
"tests": [
{
- "text": "The result variable should be an array with <h1> in it",
- "testString": "assert(result[0] == 'result variable should be an array with <h1> in it');"
+ "text": "结果变量应该是一个包含 <h1> 的数组。",
+ "testString": "assert(result[0] == '结果变量应该是一个包含 <h1> 的数组。');"
}
],
"solutions": [],
@@ -691,7 +691,7 @@
"name": "index",
"contents": [
"let text = \"/z+/ matches the letter z when it appears one or more times in a row. It would find matches in all of the following strings:",
+ "是时候暂停和测试你的新正则表达式写作技巧了。一群罪犯逃出监狱逃跑,但你不知道有多少人。但是,你知道他们和其他人在一起时会保持紧密联系。你有责任立刻找到所有的罪犯。",
+ "这里有一个示例来回顾如何做到这一点:",
+ "当字母 z 在一行中出现一次或连续多次时,正则表达式 /z+/ 会匹配到它。它会在以下所有字符串中找到匹配项:",
"\"z\"", - "But it does not find matches in the following strings since there are no letter
\"zzzzzz\"
\"ABCzzzz\"
\"zzzzABC\"
\"abczzzzzzzzzzzzzzzzzzzzzabc\"
z characters:",
+ "但是它不会在以下字符串中找到匹配项,因为它们中没有字母 z:",
"\"\"", "
\"ABC\"
\"abcabc\"
greedy regex that finds one or more criminals within a group of other people. A criminal is represented by the capital letter C."
+ "编写一个贪婪正则表达式,在一组其他人中匹配到一个或多个罪犯。罪犯由大写字母C表示。"
],
"tests": [
{
- "text": "Your regex should match one criminal (\"C\") in \"C\"",
- "testString": "assert('C'.match(reCriminals) && 'C'.match(reCriminals)[0] == 'C', 'Your regex should match one criminal (\"C\") in \"C\"');"
+ "text": "你的正则表达式应该匹配 \"C\" 中的 一个 罪犯(\"C\")。",
+ "testString": "assert('C'.match(reCriminals) && 'C'.match(reCriminals)[0] == 'C', '你的正则表达式应该匹配 \"C\" 中的 一个 罪犯(\"C\")。');"
},
{
- "text": "Your regex should match two criminals (\"CC\") in \"CC\"",
- "testString": "assert('CC'.match(reCriminals) && 'CC'.match(reCriminals)[0] == 'CC', 'Your regex should match two criminals (\"CC\") in \"CC\"');"
+ "text": "你的正则表达式应该匹配 \"CC\" 中的 两个 罪犯(\"CC\")。",
+ "testString": "assert('CC'.match(reCriminals) && 'CC'.match(reCriminals)[0] == 'CC', '你的正则表达式应该匹配 \"CC\" 中的 两个 罪犯(\"CC\")。');"
},
{
- "text": "Your regex should match three criminals (\"CCC\") in \"P1P5P4CCCP2P6P3\"",
- "testString": "assert('P1P5P4CCCP2P6P3'.match(reCriminals) && 'P1P5P4CCCP2P6P3'.match(reCriminals)[0] == 'CCC', 'Your regex should match three criminals (\"CCC\") in \"P1P5P4CCCP2P6P3\"');"
+ "text": "你的正则表达式应该匹配 \"P1P5P4CCCP2P6P3\" 中的 三个 罪犯(\"CCC\")。",
+ "testString": "assert('P1P5P4CCCP2P6P3'.match(reCriminals) && 'P1P5P4CCCP2P6P3'.match(reCriminals)[0] == 'CCC', '你的正则表达式应该匹配 \"P1P5P4CCCP2P6P3\" 中的 三个 罪犯(\"CCC\")。');"
},
{
- "text": "Your regex should match five criminals (\"CCCCC\") in \"P6P2P7P4P5CCCCCP3P1\"",
- "testString": "assert('P6P2P7P4P5CCCCCP3P1'.match(reCriminals) && 'P6P2P7P4P5CCCCCP3P1'.match(reCriminals)[0] == 'CCCCC', 'Your regex should match five criminals (\"CCCCC\") in \"P6P2P7P4P5CCCCCP3P1\"');"
+ "text": "你的正则表达式应该匹配 \"P6P2P7P4P5CCCCCP3P1\" 中的 五个 罪犯(\"CCCCC\")。",
+ "testString": "assert('P6P2P7P4P5CCCCCP3P1'.match(reCriminals) && 'P6P2P7P4P5CCCCCP3P1'.match(reCriminals)[0] == 'CCCCC', '你的正则表达式应该匹配 \"P6P2P7P4P5CCCCCP3P1\" 中的 五个 罪犯(\"CCCCC\")。');"
},
{
- "text": "Your regex should not match any criminals in \"\"",
- "testString": "assert(!reCriminals.test(''), 'Your regex should not match any criminals in \"\"');"
+ "text": "你的正则表达式在 \"\" 中不应该匹配到任何罪犯。",
+ "testString": "assert(!reCriminals.test(''), '你的正则表达式在 \"\" 中不应该匹配到任何罪犯。');"
},
{
- "text": "Your regex should not match any criminals in \"P1P2P3\"",
- "testString": "assert(!reCriminals.test('P1P2P3'), 'Your regex should not match any criminals in \"P1P2P3\"');"
+ "text": "你的正则表达式在 \"P1P2P3\" 中不应该匹配到任何罪犯。",
+ "testString": "assert(!reCriminals.test('P1P2P3'), '你的正则表达式在 \"P1P2P3\" 中不应该匹配到任何罪犯。');"
},
{
- "text": "Your regex should match fifty criminals (\"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\") in \"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3\".",
- "testString": "assert('P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3'.match(reCriminals) && 'P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3'.match(reCriminals)[0] == \"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\", 'Your regex should match fifty criminals (\"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\") in \"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3\".');"
+ "text": "你的正则表达式应该匹配 \"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3\" 中的 五十个 罪犯(\"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\")。",
+ "testString": "assert('P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3'.match(reCriminals) && 'P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3'.match(reCriminals)[0] == \"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\", '你的正则表达式应该匹配 \"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3\" 中的 五十个 罪犯(\"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\")。');"
}
],
"solutions": [],
@@ -755,7 +755,7 @@
"// example crowd gathering",
"let crowd = 'P1P2P3P4P5P6CCCP7P8P9';",
"",
- "let reCriminals = /./; // Change this line",
+ "let reCriminals = /./; // 修改这一行",
"",
"let matchedCriminals = crowd.match(reCriminals);",
"console.log(matchedCriminals);"
@@ -769,28 +769,28 @@
"id": "587d7db7367417b2b2512b9d",
"title": "Match Beginning String Patterns",
"description": [
- "Prior challenges showed that regular expressions can be used to look for a number of matches. They are also used to search for patterns in specific positions in strings.",
- "In an earlier challenge, you used the caret character (^) inside a character set to create a negated character set in the form [^thingsThatWillNotBeMatched]. Outside of a character set, the caret is used to search for patterns at the beginning of strings.",
+ "先前的挑战表明,正则表达式可以用于查找许多匹配项。它们还用于搜寻字符串中特定位置的匹配模式。",
+ "在之前的挑战中,你使用字符集中的插入符号(^)来创建一个否定字符集,形如 [^thingsThatWillNotBeMatched]。在字符集之外,插入符号用于字符串的开头搜寻匹配模式。",
"let firstString = \"Ricky is first and can be found.\";", "
let firstRegex = /^Ricky/;
firstRegex.test(firstString);
// Returns true
let notFirst = \"You can't find Ricky now.\";
firstRegex.test(notFirst);
// Returns false
caret character in a regex to find \"Cal\" only in the beginning of the string rickyAndCal."
+ "在正则表达式中使用 ^ 符号,以匹配仅在字符串 rickyAndCal 的开头出现的 \"Cal\"。"
],
"tests": [
{
- "text": "Your regex should search for \"Cal\" with a capital letter.",
- "testString": "assert(calRegex.source == \"^Cal\", 'Your regex should search for \"Cal\" with a capital letter.');"
+ "text": "你的正则表达式应该搜寻有一个大写字母的 \"Cal\"。",
+ "testString": "assert(calRegex.source == \"^Cal\", '你的正则表达式应该搜寻有一个大写字母的 \"Cal\"。');"
},
{
- "text": "Your regex should not use any flags.",
- "testString": "assert(calRegex.flags == \"\", 'Your regex should not use any flags.');"
+ "text": "你的正则表达式不应该使用任何标志。",
+ "testString": "assert(calRegex.flags == \"\", '你的正则表达式不应该使用任何标志。');"
},
{
- "text": "Your regex should match \"Cal\" at the beginning of the string.",
- "testString": "assert(calRegex.test(\"Cal and Ricky both like racing.\"), 'Your regex should match \"Cal\" at the beginning of the string.');"
+ "text": "你的正则表达式应该匹配字符串开头的 \"Cal\"。",
+ "testString": "assert(calRegex.test(\"Cal and Ricky both like racing.\"), '你的正则表达式应该匹配字符串开头的 \"Cal\"。');"
},
{
- "text": "Your regex should not match \"Cal\" in the middle of a string.",
- "testString": "assert(!calRegex.test(\"Ricky and Cal both like racing.\"), 'Your regex should not match \"Cal\" in the middle of a string.');"
+ "text": "你的正则表达式不应该匹配字符串中间的 \"Cal\"。",
+ "testString": "assert(!calRegex.test(\"Ricky and Cal both like racing.\"), '你的正则表达式不应该匹配字符串中间的 \"Cal\"。');"
}
],
"solutions": [],
@@ -804,7 +804,7 @@
"name": "index",
"contents": [
"let rickyAndCal = \"Cal and Ricky both like racing.\";",
- "let calRegex = /change/; // Change this line",
+ "let calRegex = /change/; // 修改这一行",
"let result = calRegex.test(rickyAndCal);"
],
"head": [],
@@ -816,24 +816,24 @@
"id": "587d7db7367417b2b2512b9e",
"title": "Match Ending String Patterns",
"description": [
- "In the last challenge, you learned to use the caret character to search for patterns at the beginning of strings. There is also a way to search for patterns at the end of strings.",
- "You can search the end of strings using the dollar sign character $ at the end of the regex.",
+ "在上一个挑战中,你学习了使用 ^ 符号来搜寻字符串开头的匹配模式。还有一种方法可以搜寻字符串末尾的匹配模式。",
+ "你可以使用正则表达式末尾的美元符号 $ 来搜寻字符串的结尾。",
"let theEnding = \"This is a never ending story\";", "
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = \"Sometimes a story will have to end\";
storyRegex.test(noEnding);
// Returns false
$) to match the string \"caboose\" at the end of the string caboose."
+ "使用锚字符($)在字符串 caboose 的末尾匹配 \"caboose\"。"
],
"tests": [
{
- "text": "You should search for \"caboose\" with the dollar sign $ anchor in your regex.",
- "testString": "assert(lastRegex.source == \"caboose$\", 'You should search for \"caboose\" with the dollar sign $ anchor in your regex.');"
+ "text": "你应该在正则表达式使用美元符号 $ 来搜寻 \"caboose\"。",
+ "testString": "assert(lastRegex.source == \"caboose$\", '你应该在正则表达式使用美元符号 $ 来搜寻 \"caboose\"。');"
},
{
- "text": "Your regex should not use any flags.",
- "testString": "assert(lastRegex.flags == \"\", 'Your regex should not use any flags.');"
+ "text": "你的正则表达式不应该使用任何标志。",
+ "testString": "assert(lastRegex.flags == \"\", '你的正则表达式不应该使用任何标志。');"
},
{
- "text": "You should match \"caboose\" at the end of the string \"The last car on a train is the caboose\"",
- "testString": "assert(lastRegex.test(\"The last car on a train is the caboose\"), 'You should match \"caboose\" at the end of the string \"The last car on a train is the caboose\"');"
+ "text": "你应该在字符串 \"The last car on a train is the caboose\" 的末尾匹配 \"caboose\"。",
+ "testString": "assert(lastRegex.test(\"The last car on a train is the caboose\"), '你应该在字符串 \"The last car on a train is the caboose\" 的末尾匹配 \"caboose\"。');"
}
],
"solutions": [],
@@ -847,7 +847,7 @@
"name": "index",
"contents": [
"let caboose = \"The last car on a train is the caboose\";",
- "let lastRegex = /change/; // Change this line",
+ "let lastRegex = /change/; // 修改这一行",
"let result = lastRegex.test(caboose);"
],
"head": [],
@@ -859,33 +859,33 @@
"id": "587d7db7367417b2b2512b9f",
"title": "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 (_).",
+ "使用字符类,你可以使用 [a-z] 搜寻字母表中的所有字母。这种字符类是很常见的,它有一个快捷键,尽管它也包含一些额外的字符。",
+ "JavaScript 中与字母表匹配的最接近的字符类是 \\w。这个快捷键等同于 [A-Za-z0-9_]。这个字符类匹配大小写字母和数字。注意,它也包括下划线字符(_)。",
"let longHand = /[A-Za-z0-9_]+/;", - "These shortcut character classes are also known as
let shortHand = /\\w+/;
let numbers = \"42\";
let varNames = \"important_var\";
longHand.test(numbers); // Returns true
shortHand.test(numbers); // Returns true
longHand.test(varNames); // Returns true
shortHand.test(varNames); // Returns true
shorthand character classes.",
+ "这些快捷字符类也被称为速记字符类。",
"\\w to count the number of alphanumeric characters in various quotes and strings."
+ "使用速记字符类 \\w 来计算不同引号和字符串中字母数字字符的数量。"
],
"tests": [
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(alphabetRegexV2.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(alphabetRegexV2.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find 31 alphanumeric characters in \"The five boxing wizards jump quickly.\"",
- "testString": "assert(\"The five boxing wizards jump quickly.\".match(alphabetRegexV2).length === 31, 'Your regex should find 31 alphanumeric characters in \"The five boxing wizards jump quickly.\"');"
+ "text": "你的正则表达式应该在 \"The five boxing wizards jump quickly.\" 中匹配到 31 个字母数字字符。",
+ "testString": "assert(\"The five boxing wizards jump quickly.\".match(alphabetRegexV2).length === 31, '你的正则表达式应该在 \"The five boxing wizards jump quickly.\" 中匹配到 31 个字母数字字符。');"
},
{
- "text": "Your regex should find 32 alphanumeric characters in \"Pack my box with five dozen liquor jugs.\"",
- "testString": "assert(\"Pack my box with five dozen liquor jugs.\".match(alphabetRegexV2).length === 32, 'Your regex should find 32 alphanumeric characters in \"Pack my box with five dozen liquor jugs.\"');"
+ "text": "你的正则表达式应该在 \"Pack my box with five dozen liquor jugs.\" 中匹配到 32 个字母数字字符。",
+ "testString": "assert(\"Pack my box with five dozen liquor jugs.\".match(alphabetRegexV2).length === 32, '你的正则表达式应该在 \"Pack my box with five dozen liquor jugs.\" 中匹配到 32 个字母数字字符。');"
},
{
- "text": "Your regex should find 30 alphanumeric characters in \"How vexingly quick daft zebras jump!\"",
- "testString": "assert(\"How vexingly quick daft zebras jump!\".match(alphabetRegexV2).length === 30, 'Your regex should find 30 alphanumeric characters in \"How vexingly quick daft zebras jump!\"');"
+ "text": "你的正则表达式应该在 \"How vexingly quick daft zebras jump!\" 中匹配到 30 个字母数字字符。",
+ "testString": "assert(\"How vexingly quick daft zebras jump!\".match(alphabetRegexV2).length === 30, '你的正则表达式应该在 \"How vexingly quick daft zebras jump!\" 中匹配到 30 个字母数字字符。');"
},
{
- "text": "Your regex should find 36 alphanumeric characters in \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\"",
- "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 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\"');"
+ "text": "你的正则表达式应该在 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\" 中匹配到 36 个字母数字字符。",
+ "testString": "assert(\"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\".match(alphabetRegexV2).length === 36, '你的正则表达式应该在 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\" 中匹配到 36 个字母数字字符。');"
}
],
"solutions": [],
@@ -899,7 +899,7 @@
"name": "index",
"contents": [
"let quoteSample = \"The five boxing wizards jump quickly.\";",
- "let alphabetRegexV2 = /change/; // Change this line",
+ "let alphabetRegexV2 = /change/; // 修改这一行",
"let result = quoteSample.match(alphabetRegexV2).length;"
],
"head": [],
@@ -911,32 +911,32 @@
"id": "587d7db8367417b2b2512ba0",
"title": "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_].",
+ "你已经了解到可以使用快捷键 \\w 来匹配字母数字 [A-Za-z0-9_]。不过,有可能你想要搜寻的自然匹配模式与字母数字相反。",
+ "你可以使用 \\W 搜寻和 \\w 相反的匹配模式。注意,相反匹配模式使用大写字母。此快捷键与 [^A-Za-z0-9_] 是一样的。",
"let shortHand = /\\W/;", "
let numbers = \"42%\";
let sentence = \"Coding!\";
numbers.match(shortHand); // Returns [\"%\"]
sentence.match(shortHand); // Returns [\"!\"]
\\W to count the number of non-alphanumeric characters in various quotes and strings."
+ "使用速记字符类 \\W 来计算不同引号和字符串中非字母数字字符的数量。"
],
"tests": [
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(nonAlphabetRegex.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(nonAlphabetRegex.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find 6 non-alphanumeric characters in \"The five boxing wizards jump quickly.\".",
- "testString": "assert(\"The five boxing wizards jump quickly.\".match(nonAlphabetRegex).length == 6, 'Your regex should find 6 non-alphanumeric characters in \"The five boxing wizards jump quickly.\".');"
+ "text": "你的正则表达式应该在 \"The five boxing wizards jump quickly.\" 中匹配到 6 个非字母数字字符。",
+ "testString": "assert(\"The five boxing wizards jump quickly.\".match(nonAlphabetRegex).length == 6, '你的正则表达式应该在 \"The five boxing wizards jump quickly.\" 中匹配到 6 个非字母数字字符。');"
},
{
- "text": "Your regex should find 8 non-alphanumeric characters in \"Pack my box with five dozen liquor jugs.\"",
- "testString": "assert(\"Pack my box with five dozen liquor jugs.\".match(nonAlphabetRegex).length == 8, 'Your regex should find 8 non-alphanumeric characters in \"Pack my box with five dozen liquor jugs.\"');"
+ "text": "你的正则表达式应该在 \"Pack my box with five dozen liquor jugs.\" 中匹配到 8 个非字母数字字符。",
+ "testString": "assert(\"Pack my box with five dozen liquor jugs.\".match(nonAlphabetRegex).length == 8, '你的正则表达式应该在 \"Pack my box with five dozen liquor jugs.\" 中匹配到 8 个非字母数字字符。');"
},
{
- "text": "Your regex should find 6 non-alphanumeric characters in \"How vexingly quick daft zebras jump!\"",
- "testString": "assert(\"How vexingly quick daft zebras jump!\".match(nonAlphabetRegex).length == 6, 'Your regex should find 6 non-alphanumeric characters in \"How vexingly quick daft zebras jump!\"');"
+ "text": "你的正则表达式应该在 \"How vexingly quick daft zebras jump!\" 中匹配到 6 个非字母数字字符。",
+ "testString": "assert(\"How vexingly quick daft zebras jump!\".match(nonAlphabetRegex).length == 6, '你的正则表达式应该在 \"How vexingly quick daft zebras jump!\" 中匹配到 6 个非字母数字字符。');"
},
{
- "text": "Your regex should find 12 non-alphanumeric characters in \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\"",
- "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 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\"');"
+ "text": "你的正则表达式应该在 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\" 中匹配到 12 个非字母数字字符。",
+ "testString": "assert(\"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\".match(nonAlphabetRegex).length == 12, '你的正则表达式应该在 \"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.\" 中匹配到 12 个非字母数字字符。');"
}
],
"solutions": [],
@@ -950,7 +950,7 @@
"name": "index",
"contents": [
"let quoteSample = \"The five boxing wizards jump quickly.\";",
- "let nonAlphabetRegex = /change/; // Change this line",
+ "let nonAlphabetRegex = /change/; // 修改这一行",
"let result = quoteSample.match(nonAlphabetRegex).length;"
],
"head": [],
@@ -962,43 +962,43 @@
"id": "5d712346c441eddfaeb5bdef",
"title": "Match All Numbers",
"description": [
- "You've learned shortcuts for common string patterns like alphanumerics. Another common pattern is looking for just digits or numbers.",
- "The shortcut to look for digit characters is \\d, with a lowercase d. This is equal to the character class [0-9], which looks for a single character of any number between zero and nine.",
+ "你已经了解了常见字符串匹配模式的快捷键,如字母数字。另一个常见的匹配模式是只寻找数字。",
+ "查找数字字符的快捷键是 \\d,是小写的 d。这等同于字符类 [0-9],它查找 0 到 9 之间任意数字的单个字符。",
"\\d to count how many digits are in movie titles. Written out numbers (\"six\" instead of 6) do not count."
+ "使用速记字符类 \\d 来计算电影标题中有多少个数字。书面数字(\"six\" 而不是 6)不计算在内。"
],
"tests": [
{
- "text": "Your regex should use the shortcut character to match digit characters",
- "testString": "assert(/\\\\d/.test(numRegex.source), 'Your regex should use the shortcut character to match digit characters');"
+ "text": "你的正则表达式应该使用快捷字符来匹配数字字符。",
+ "testString": "assert(/\\\\d/.test(numRegex.source), '你的正则表达式应该使用快捷字符来匹配数字字符。');"
},
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(numRegex.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(numRegex.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find 1 digit in \"9\".",
- "testString": "assert(\"9\".match(numRegex).length == 1, 'Your regex should find 1 digit in \"9\".');"
+ "text": "你的正则表达式应该在 \"9\" 中匹配到 1 个数字。",
+ "testString": "assert(\"9\".match(numRegex).length == 1, '你的正则表达式应该在 \"9\" 中匹配到 1 个数字。');"
},
{
- "text": "Your regex should find 2 digits in \"Catch 22\".",
- "testString": "assert(\"Catch 22\".match(numRegex).length == 2, 'Your regex should find 2 digits in \"Catch 22\".');"
+ "text": "你的正则表达式应该在 \"Catch 22\" 中匹配到 2 个数字。",
+ "testString": "assert(\"Catch 22\".match(numRegex).length == 2, '你的正则表达式应该在 \"Catch 22\" 中匹配到 2 个数字。');"
},
{
- "text": "Your regex should find 3 digits in \"101 Dalmatians\".",
- "testString": "assert(\"101 Dalmatians\".match(numRegex).length == 3, 'Your regex should find 3 digits in \"101 Dalmatians\".');"
+ "text": "你的正则表达式应该在 \"101 Dalmatians\" 中匹配到 3 个数字。",
+ "testString": "assert(\"101 Dalmatians\".match(numRegex).length == 3, '你的正则表达式应该在 \"101 Dalmatians\" 中匹配到 3 个数字。');"
},
{
- "text": "Your regex should find no digits in \"One, Two, Three\".",
- "testString": "assert(\"One, Two, Three\".match(numRegex) == null, 'Your regex should find no digits in \"One, Two, Three\".');"
+ "text": "你的正则表达式在 \"One, Two, Three\" 中应该匹配不到数字。",
+ "testString": "assert(\"One, Two, Three\".match(numRegex) == null, '你的正则表达式在 \"One, Two, Three\" 中应该匹配不到数字。');"
},
{
- "text": "Your regex should find 2 digits in \"21 Jump Street\".",
- "testString": "assert(\"21 Jump Street\".match(numRegex).length == 2, 'Your regex should find 2 digits in \"21 Jump Street\".');"
+ "text": "你的正则表达式应该在 \"21 Jump Street\" 中匹配到 2 个数字。",
+ "testString": "assert(\"21 Jump Street\".match(numRegex).length == 2, '你的正则表达式应该在 \"21 Jump Street\" 中匹配到 2 个数字。');"
},
{
- "text": "Your regex should find 4 digits in \"2001: A Space Odyssey\".",
- "testString": "assert(\"2001: A Space Odyssey\".match(numRegex).length == 4, 'Your regex should find 4 digits in \"2001: A Space Odyssey\".');"
+ "text": "你的正则表达式应该在 \"2001: A Space Odyssey\" 中匹配到 4 个数字。",
+ "testString": "assert(\"2001: A Space Odyssey\".match(numRegex).length == 4, '你的正则表达式应该在 \"2001: A Space Odyssey\" 中匹配到 4 个数字。');"
}
],
"solutions": [],
@@ -1012,7 +1012,7 @@
"name": "index",
"contents": [
"let numString = \"Your sandwich will be $5.00\";",
- "let numRegex = /change/; // Change this line",
+ "let numRegex = /change/; // 修改这一行",
"let result = numString.match(numRegex).length;"
],
"head": [],
@@ -1024,43 +1024,43 @@
"id": "587d7db8367417b2b2512ba1",
"title": "Match All Non-Numbers",
"description": [
- "The last challenge showed how to search for digits using the shortcut \\d with a lowercase d. You can also search for non-digits using a similar shortcut that uses an uppercase D instead.",
- "The shortcut to look for non-digit characters is \\D. This is equal to the character class [^0-9], which looks for a single character that is not a number between zero and nine.",
+ "上一项挑战中展示了如何使用带有小写 d 的快捷键 \\d 来搜寻数字。你也可以使用类似的快捷键来搜寻非数字,该快捷键使用大写的 D。",
+ "查找非数字字符的快捷键是 \\D。这等同于字符串 [^0-9],它查找不是 0 - 9 之间数字的单个字符。",
"\\D to count how many non-digits are in movie titles."
+ "使用非数字速记字符类 \\D 来计算电影标题中有多少非数字。"
],
"tests": [
{
- "text": "Your regex should use the shortcut character to match non-digit characters",
- "testString": "assert(/\\\\D/.test(noNumRegex.source), 'Your regex should use the shortcut character to match non-digit characters');"
+ "text": "你的正则表达式应该使用快捷字符来匹配非数字字符。",
+ "testString": "assert(/\\\\D/.test(noNumRegex.source), '你的正则表达式应该使用快捷字符来匹配非数字字符。');"
},
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(noNumRegex.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(noNumRegex.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find no non-digits in \"9\".",
- "testString": "assert(\"9\".match(noNumRegex) == null, 'Your regex should find no non-digits in \"9\".');"
+ "text": "你的正则表达式在 \"9\" 中应该匹配不到非数字。",
+ "testString": "assert(\"9\".match(noNumRegex) == null, '你的正则表达式在 \"9\" 中应该匹配不到非数字。');"
},
{
- "text": "Your regex should find 6 non-digits in \"Catch 22\".",
- "testString": "assert(\"Catch 22\".match(noNumRegex).length == 6, 'Your regex should find 6 non-digits in \"Catch 22\".');"
+ "text": "你的正则表达式应该在 \"Catch 22\" 中匹配到 6 个非数字。",
+ "testString": "assert(\"Catch 22\".match(noNumRegex).length == 6, '你的正则表达式应该在 \"Catch 22\" 中匹配到 6 个非数字。');"
},
{
- "text": "Your regex should find 11 non-digits in \"101 Dalmatians\".",
- "testString": "assert(\"101 Dalmatians\".match(noNumRegex).length == 11, 'Your regex should find 11 non-digits in \"101 Dalmatians\".');"
+ "text": "你的正则表达式应该在 \"101 Dalmatians\" 中匹配到 11 个非数字。",
+ "testString": "assert(\"101 Dalmatians\".match(noNumRegex).length == 11, '你的正则表达式应该在 \"101 Dalmatians\" 中匹配到 11 个非数字。');"
},
{
- "text": "Your regex should find 15 non-digits in \"One, Two, Three\".",
- "testString": "assert(\"One, Two, Three\".match(noNumRegex).length == 15, 'Your regex should find 15 non-digits in \"One, Two, Three\".');"
+ "text": "你的正则表达式应该在 \"One, Two, Three\" 中匹配到 15 个非数字。",
+ "testString": "assert(\"One, Two, Three\".match(noNumRegex).length == 15, '你的正则表达式应该在 \"One, Two, Three\" 中匹配到 15 个非数字。');"
},
{
- "text": "Your regex should find 12 non-digits in \"21 Jump Street\".",
- "testString": "assert(\"21 Jump Street\".match(noNumRegex).length == 12, 'Your regex should find 12 non-digits in \"21 Jump Street\".');"
+ "text": "你的正则表达式应该在 \"21 Jump Street\" 中匹配到 12 个非数字。",
+ "testString": "assert(\"21 Jump Street\".match(noNumRegex).length == 12, '你的正则表达式应该在 \"21 Jump Street\" 中匹配到 12 个非数字。');"
},
{
- "text": "Your regex should find 17 non-digits in \"2001: A Space Odyssey\".",
- "testString": "assert(\"2001: A Space Odyssey\".match(noNumRegex).length == 17, 'Your regex should find 17 non-digits in \"2001: A Space Odyssey\".');"
+ "text": "你的正则表达式应该在 \"2001: A Space Odyssey\" 中匹配到 17 个非数字。",
+ "testString": "assert(\"2001: A Space Odyssey\".match(noNumRegex).length == 17, '你的正则表达式应该在 \"2001: A Space Odyssey\" 中匹配到 17 个非数字。');"
}
],
"solutions": [],
@@ -1074,7 +1074,7 @@
"name": "index",
"contents": [
"let numString = \"Your sandwich will be $5.00\";",
- "let noNumRegex = /change/; // Change this line",
+ "let noNumRegex = /change/; // 修改这一行",
"let result = numString.match(noNumRegex).length;"
],
"head": [],
@@ -1086,38 +1086,38 @@
"id": "587d7db8367417b2b2512ba2",
"title": "Restrict Possible Usernames",
"description": [
- "Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.",
- "You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.",
- "1) The only numbers in the username have to be at the end. There can be zero or more of them at the end.",
- "2) Username letters can be lowercase and uppercase.",
- "3) Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.",
+ "用户名在互联网上随处可见。它们是用户在自己喜欢的网站上的唯一身份。",
+ "你需要检查数据库中的所有用户名。以下是用户在创建用户名时必须遵守的一些简单规则。",
+ "1) 用户名中唯一的数字必须在最后。 最后可以有零个或多个。",
+ "2) 用户名字母可以是小写字母和大写字母。",
+ "3) 用户名长度必须至少为两个字符。两位用户名只能使用字母字符。",
"userCheck to fit the constraints listed above."
+ "修改正则表达式 userCheck 以适合上面列出的约束。"
],
"tests": [
{
- "text": "Your regex should match JACK",
- "testString": "assert(userCheck.test(\"JACK\"), 'Your regex should match JACK');"
+ "text": "你的正则表达式应该匹配 JACK。",
+ "testString": "assert(userCheck.test(\"JACK\"), '你的正则表达式应该匹配 JACK。');"
},
{
- "text": "Your regex should not match J",
- "testString": "assert(!userCheck.test(\"J\"), 'Your regex should not match J');"
+ "text": "你的正则表达式不应该匹配 J。",
+ "testString": "assert(!userCheck.test(\"J\"), '你的正则表达式不应该匹配 J。');"
},
{
- "text": "Your regex should match Oceans11",
- "testString": "assert(userCheck.test(\"Oceans11\"), 'Your regex should match Oceans11');"
+ "text": "你的正则表达式应该匹配 Oceans11。",
+ "testString": "assert(userCheck.test(\"Oceans11\"), '你的正则表达式应该匹配 Oceans11。');"
},
{
- "text": "Your regex should match RegexGuru",
- "testString": "assert(userCheck.test(\"RegexGuru\"), 'Your regex should match RegexGuru');"
+ "text": "你的正则表达式应该匹配 RegexGuru。",
+ "testString": "assert(userCheck.test(\"RegexGuru\"), '你的正则表达式应该匹配 RegexGuru。');"
},
{
- "text": "Your regex should not match 007",
- "testString": "assert(!userCheck.test(\"007\"), 'Your regex should not match 007');"
+ "text": "你的正则表达式不应该匹配 007。",
+ "testString": "assert(!userCheck.test(\"007\"), '你的正则表达式不应该匹配 007。');"
},
{
- "text": "Your regex should not match 9",
- "testString": "assert(!userCheck.test(\"9\"), 'Your regex should not match 9');"
+ "text": "你的正则表达式不应该匹配 9。",
+ "testString": "assert(!userCheck.test(\"9\"), '你的正则表达式不应该匹配 9。');"
}
],
"solutions": [],
@@ -1131,7 +1131,7 @@
"name": "index",
"contents": [
"let username = \"JackOfAllTrades\";",
- "let userCheck = /change/; // Change this line",
+ "let userCheck = /change/; // 修改这一行",
"let result = userCheck.test(username);"
],
"head": [],
@@ -1143,28 +1143,28 @@
"id": "587d7db8367417b2b2512ba3",
"title": "Match Whitespace",
"description": [
- "The challenges so far have covered matching letters of the alphabet and numbers. You can also match the whitespace or spaces between letters.",
- "You can search for whitespace using \\s, which is a lowercase s. This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters. You can think of it as similar to the character class [ \\r\\t\\f\\n\\v].",
+ "迄今为止的挑战包括匹配的字母和数字。你还可以匹配字母之间的空格。",
+ "你可以使用 \\s 搜寻空格,其中 s 是小写。此匹配模式不仅匹配空格,还匹配回车符、制表符、换页符和换行符,你可以将其视为与字符类 [ \\r\\t\\f\\n\\v] 类似。",
"let whiteSpace = \"Whitespace. Whitespace everywhere!\"", "
let spaceRegex = /\\s/g;
whiteSpace.match(spaceRegex);
// Returns [\" \", \" \"]
countWhiteSpace to look for multiple whitespace characters in a string."
+ "修改正则表达式 countWhiteSpace 查找字符串中的多个空白字符。"
],
"tests": [
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(countWhiteSpace.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(countWhiteSpace.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find eight spaces in \"Men are from Mars and women are from Venus.\"",
- "testString": "assert(\"Men are from Mars and women are from Venus.\".match(countWhiteSpace).length == 8, 'Your regex should find eight spaces in \"Men are from Mars and women are from Venus.\"');"
+ "text": "你的正则表达式应该在 \"Men are from Mars and women are from Venus.\" 中匹配到 8 个空白字符。",
+ "testString": "assert(\"Men are from Mars and women are from Venus.\".match(countWhiteSpace).length == 8, '你的正则表达式应该在 \"Men are from Mars and women are from Venus.\" 中匹配到 8 个空白字符。');"
},
{
- "text": "Your regex should find three spaces in \"Space: the final frontier.\"",
- "testString": "assert(\"Space: the final frontier.\".match(countWhiteSpace).length == 3, 'Your regex should find three spaces in \"Space: the final frontier.\"');"
+ "text": "你的正则表达式应该在 \"Space: the final frontier.\" 中匹配到 3 个空白字符。",
+ "testString": "assert(\"Space: the final frontier.\".match(countWhiteSpace).length == 3, '你的正则表达式应该在 \"Space: the final frontier.\" 中匹配到 3 个空白字符。');"
},
{
- "text": "Your regex should find no spaces in \"MindYourPersonalSpace\"",
- "testString": "assert(\"MindYourPersonalSpace\".match(countWhiteSpace) == null, 'Your regex should find no spaces in \"MindYourPersonalSpace\"');"
+ "text": "你的正则表达式在 \"MindYourPersonalSpace\" 中应该匹配不到空白字符。",
+ "testString": "assert(\"MindYourPersonalSpace\".match(countWhiteSpace) == null, '你的正则表达式在 \"MindYourPersonalSpace\" 中应该匹配不到空白字符。');"
}
],
"solutions": [],
@@ -1178,7 +1178,7 @@
"name": "index",
"contents": [
"let sample = \"Whitespace is important in separating words\";",
- "let countWhiteSpace = /change/; // Change this line",
+ "let countWhiteSpace = /change/; // 修改这一行",
"let result = sample.match(countWhiteSpace);"
],
"head": [],
@@ -1190,28 +1190,28 @@
"id": "587d7db9367417b2b2512ba4",
"title": "Match Non-Whitespace Characters",
"description": [
- "You learned about searching for whitespace using \\s, with a lowercase s. You can also search for everything except whitespace.",
- "Search for non-whitespace using \\S, which is an uppercase s. This pattern will not match whitespace, carriage return, tab, form feed, and new line characters. You can think of it being similar to the character class [^ \\r\\t\\f\\n\\v].",
+ "你已经学会了如何使用带有小写 s 的快捷键 \\s 来搜寻空白字符。你也可以搜寻除了空格之外的所有内容。",
+ "使用 \\S 搜寻非空白字符,其中 s 是大写。此匹配模式将不匹配空格、回车符、制表符、换页符和换行符。你可以认为这类似于字符类 [^ \\r\\t\\f\\n\\v]。",
"let whiteSpace = \"Whitespace. Whitespace everywhere!\"", "
let nonSpaceRegex = /\\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
countNonWhiteSpace to look for multiple non-whitespace characters in a string."
+ "修改正则表达式 countNonWhiteSpace 以查找字符串中的多个非空字符。"
],
"tests": [
{
- "text": "Your regex should use the global flag.",
- "testString": "assert(countNonWhiteSpace.global, 'Your regex should use the global flag.');"
+ "text": "你的正则表达式应该使用全局状态修正符。",
+ "testString": "assert(countNonWhiteSpace.global, '你的正则表达式应该使用全局状态修正符。');"
},
{
- "text": "Your regex should find 35 non-spaces in \"Men are from Mars and women are from Venus.\"",
- "testString": "assert(\"Men are from Mars and women are from Venus.\".match(countNonWhiteSpace).length == 35, 'Your regex should find 35 non-spaces in \"Men are from Mars and women are from Venus.\"');"
+ "text": "你的正则表达式应该在 \"Men are from Mars and women are from Venus.\" 中匹配到 35 个非空白字符。",
+ "testString": "assert(\"Men are from Mars and women are from Venus.\".match(countNonWhiteSpace).length == 35, '你的正则表达式应该在 \"Men are from Mars and women are from Venus.\" 中匹配到 35 个非空白字符。');"
},
{
- "text": "Your regex should find 23 non-spaces in \"Space: the final frontier.\"",
- "testString": "assert(\"Space: the final frontier.\".match(countNonWhiteSpace).length == 23, 'Your regex should find 23 non-spaces in \"Space: the final frontier.\"');"
+ "text": "你的正则表达式应该在 \"Space: the final frontier.\" 中匹配到 23 个非空白字符。",
+ "testString": "assert(\"Space: the final frontier.\".match(countNonWhiteSpace).length == 23, '你的正则表达式应该在 \"Space: the final frontier.\" 中匹配到 23 个非空白字符。');"
},
{
- "text": "Your regex should find 21 non-spaces in \"MindYourPersonalSpace\"",
- "testString": "assert(\"MindYourPersonalSpace\".match(countNonWhiteSpace).length == 21, 'Your regex should find 21 non-spaces in \"MindYourPersonalSpace\"');"
+ "text": "你的正则表达式应该在 \"MindYourPersonalSpace\" 中匹配到 21 个非空白字符。",
+ "testString": "assert(\"MindYourPersonalSpace\".match(countNonWhiteSpace).length == 21, '你的正则表达式应该在 \"MindYourPersonalSpace\" 中匹配到 21 个非空白字符。');"
}
],
"solutions": [],
@@ -1225,7 +1225,7 @@
"name": "index",
"contents": [
"let sample = \"Whitespace is important in separating words\";",
- "let countNonWhiteSpace = /change/; // Change this line",
+ "let countNonWhiteSpace = /change/; // 修改这一行",
"let result = sample.match(countNonWhiteSpace);"
],
"head": [],
@@ -1237,41 +1237,41 @@
"id": "587d7db9367417b2b2512ba5",
"title": "Specify Upper and Lower Number of Matches",
"description": [
- "Recall that you use the plus sign + to look for one or more characters and the asterisk * to look for zero or more characters. These are convenient but sometimes you want to match a certain range of patterns.",
- "You can specify the lower and upper number of patterns with quantity specifiers. Quantity specifiers are used with curly brackets ({ and }). You put two numbers between the curly brackets - for the lower and upper number of patterns.",
- "For example, to match only the letter a appearing between 3 and 5 times in the string \"ah\", your regex would be /a{3,5}h/.",
+ "回想一下,你使用加号 + 查找一个或多个字符,使用星号 * 查找零个或多个字符。这些都很方便,但有时你需要匹配一定范围的匹配模式。",
+ "你可以使用数量说明符指定匹配模式的上下限。数量说明符与花括号({ 和 })一起使用。你在花括号之间放两个数字,作为匹配模式的上下限数字。",
+ "例如,要在字符串 \"ah\" 中匹配仅出现 3 到 5 次的字母 a,你的正则表达式应为 /a{3,5}h/。",
"let A4 = \"aaaah\";", "
let A2 = \"aah\";
let multipleA = /a{3,5}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
ohRegex to match only 3 to 6 letter h's in the word \"Oh no\"."
+ "修改正则表达式 ohRegex 以匹配在 \"Oh no\" 中仅出现 3 到 6 次的字母 h。"
],
"tests": [
{
- "text": "Your regex should use curly brackets.",
- "testString": "assert(ohRegex.source.match(/{.*?}/).length > 0, 'Your regex should use curly brackets.');"
+ "text": "你的正则表达式应该使用花括号。",
+ "testString": "assert(ohRegex.source.match(/{.*?}/).length > 0, '你的正则表达式应该使用花括号。');"
},
{
- "text": "Your regex should not match \"Ohh no\"",
- "testString": "assert(!ohRegex.test(\"Ohh no\"), 'Your regex should not match \"Ohh no\"');"
+ "text": "你的正则表达式不应该匹配 \"Ohh no\"。",
+ "testString": "assert(!ohRegex.test(\"Ohh no\"), '你的正则表达式不应该匹配 \"Ohh no\"。');"
},
{
- "text": "Your regex should match \"Ohhh no\"",
- "testString": "assert(ohRegex.test(\"Ohhh no\"), 'Your regex should match \"Ohhh no\"');"
+ "text": "你的正则表达式应该匹配 \"Ohhh no\"。",
+ "testString": "assert(ohRegex.test(\"Ohhh no\"), '你的正则表达式应该匹配 \"Ohhh no\"。');"
},
{
- "text": "Your regex should match \"Ohhhh no\"",
- "testString": "assert(ohRegex.test(\"Ohhhh no\"), 'Your regex should match \"Ohhhh no\"');"
+ "text": "你的正则表达式应该匹配 \"Ohhhh no\"。",
+ "testString": "assert(ohRegex.test(\"Ohhhh no\"), '你的正则表达式应该匹配 \"Ohhhh no\"。');"
},
{
- "text": "Your regex should match \"Ohhhhh no\"",
- "testString": "assert(ohRegex.test(\"Ohhhhh no\"), 'Your regex should match \"Ohhhhh no\"');"
+ "text": "你的正则表达式应该匹配 \"Ohhhhh no\"。",
+ "testString": "assert(ohRegex.test(\"Ohhhhh no\"), '你的正则表达式应该匹配 \"Ohhhhh no\"。');"
},
{
- "text": "Your regex should match \"Ohhhhhh no\"",
- "testString": "assert(ohRegex.test(\"Ohhhhhh no\"), 'Your regex should match \"Ohhhhhh no\"');"
+ "text": "你的正则表达式应该匹配 \"Ohhhhhh no\"。",
+ "testString": "assert(ohRegex.test(\"Ohhhhhh no\"), '你的正则表达式应该匹配 \"Ohhhhhh no\"。');"
},
{
- "text": "Your regex should not match \"Ohhhhhhh no\"",
- "testString": "assert(!ohRegex.test(\"Ohhhhhhh no\"), 'Your regex should not match \"Ohhhhhhh no\"');"
+ "text": "你的正则表达式不应该匹配 \"Ohhhhhhh no\"。",
+ "testString": "assert(!ohRegex.test(\"Ohhhhhhh no\"), '你的正则表达式不应该匹配 \"Ohhhhhhh no\"。');"
}
],
"solutions": [],
@@ -1285,7 +1285,7 @@
"name": "index",
"contents": [
"let ohStr = \"Ohhh no\";",
- "let ohRegex = /change/; // Change this line",
+ "let ohRegex = /change/; // 修改这一行",
"let result = ohRegex.test(ohStr);"
],
"head": [],
@@ -1297,41 +1297,41 @@
"id": "587d7db9367417b2b2512ba6",
"title": "Specify Only the Lower Number of Matches",
"description": [
- "You can specify the lower and upper number of patterns with quantity specifiers using curly brackets. Sometimes you only want to specify the lower number of patterns with no upper limit.",
- "To only specify the lower number of patterns, keep the first number followed by a comma.",
- "For example, to match only the string \"hah\" with the letter a appearing at least 3 times, your regex would be /ha{3,}h/.",
+ "你可以使用带有花括号的数量说明符来指定匹配模式的上下限。有时候你只想指定匹配模式的下限而没有上限。",
+ "要只指定匹配模式的下限,在第一个数字后面跟一个逗号即可。",
+ "例如,要匹配字母 a 出现至少 3 次的唯一字符串 \"hah\",你的正则表达式应该是 /ha{3,}h/。",
"let A4 = \"haaaah\";", "
let A2 = \"haah\";
let A100 = \"h\" + \"a\".repeat(100) + \"h\";
let multipleA = /ha{3,}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
multipleA.test(A100); // Returns true
haRegex to match the word \"Hazzah\" only when it has four or more letter z's."
+ "修改正则表达式 haRegex,匹配包含四个或更多字母 z 的单词 \"Hazzah\"。"
],
"tests": [
{
- "text": "Your regex should use curly brackets.",
- "testString": "assert(haRegex.source.match(/{.*?}/).length > 0, 'Your regex should use curly brackets.');"
+ "text": "你的正则表达式应该使用花括号。",
+ "testString": "assert(haRegex.source.match(/{.*?}/).length > 0, '你的正则表达式应该使用花括号。');"
},
{
- "text": "Your regex should not match \"Hazzah\"",
- "testString": "assert(!haRegex.test(\"Hazzah\"), 'Your regex should not match \"Hazzah\"');"
+ "text": "你的正则表达式不应该匹配 \"Hazzah\"。",
+ "testString": "assert(!haRegex.test(\"Hazzah\"), '你的正则表达式不应该匹配 \"Hazzah\"。');"
},
{
- "text": "Your regex should not match \"Hazzzah\"",
- "testString": "assert(!haRegex.test(\"Hazzzah\"), 'Your regex should not match \"Hazzzah\"');"
+ "text": "你的正则表达式不应该匹配 \"Hazzzah\"。",
+ "testString": "assert(!haRegex.test(\"Hazzzah\"), '你的正则表达式不应该匹配 \"Hazzzah\"。');"
},
{
- "text": "Your regex should match \"Hazzzzah\"",
- "testString": "assert(haRegex.test(\"Hazzzzah\"), 'Your regex should match \"Hazzzzah\"');"
+ "text": "你的正则表达式应该匹配 \"Hazzzzah\"。",
+ "testString": "assert(haRegex.test(\"Hazzzzah\"), '你的正则表达式应该匹配 \"Hazzzzah\"。');"
},
{
- "text": "Your regex should match \"Hazzzzzah\"",
- "testString": "assert(haRegex.test(\"Hazzzzzah\"), 'Your regex should match \"Hazzzzzah\"');"
+ "text": "你的正则表达式应该匹配 \"Hazzzzzah\"。",
+ "testString": "assert(haRegex.test(\"Hazzzzzah\"), '你的正则表达式应该匹配 \"Hazzzzzah\"。');"
},
{
- "text": "Your regex should match \"Hazzzzzzah\"",
- "testString": "assert(haRegex.test(\"Hazzzzzzah\"), 'Your regex should match \"Hazzzzzzah\"');"
+ "text": "你的正则表达式应该匹配 \"Hazzzzzzah\"。",
+ "testString": "assert(haRegex.test(\"Hazzzzzzah\"), '你的正则表达式应该匹配 \"Hazzzzzzah\"。');"
},
{
- "text": "Your regex should match \"Hazzah\" with 30 z\\'s in it.",
- "testString": "assert(haRegex.test(\"Ha\" + \"z\".repeat(30) + \"ah\"), 'Your regex should match \"Hazzah\" with 30 z\\'s in it.');"
+ "text": "你的正则表达式不应该匹配拥有 30 个字母 z 的 \"Hazzah\"。",
+ "testString": "assert(haRegex.test(\"Ha\" + \"z\".repeat(30) + \"ah\"), '你的正则表达式不应该匹配拥有 30 个字母 z 的 \"Hazzah\"。');"
}
],
"solutions": [],
@@ -1345,7 +1345,7 @@
"name": "index",
"contents": [
"let haStr = \"Hazzzzah\";",
- "let haRegex = /change/; // Change this line",
+ "let haRegex = /change/; // 修改这一行",
"let result = haRegex.test(haStr);"
],
"head": [],
@@ -1357,37 +1357,37 @@
"id": "587d7db9367417b2b2512ba7",
"title": "Specify Exact Number of Matches",
"description": [
- "You can specify the lower and upper number of patterns with quantity specifiers using curly brackets. Sometimes you only want a specific number of matches.",
- "To specify a certain number of patterns, just have that one number between the curly brackets.",
- "For example, to match only the word \"hah\" with the letter a 3 times, your regex would be /ha{3}h/.",
+ "你可以使用带有花括号的数量说明符来指定匹配模式的上下限。有时你只需要特定数量的匹配。",
+ "要指定一定数量的匹配模式,只需在大括号之间放置一个数字。",
+ "例如,要只匹配字母 a 出现 3 次的单词 \"hah\",你的正则表达式应为 /ha{3}h/。",
"let A4 = \"haaaah\";", "
let A3 = \"haaah\";
let A100 = \"h\" + \"a\".repeat(100) + \"h\";
let multipleHA = /a{3}h/;
multipleHA.test(A4); // Returns false
multipleHA.test(A3); // Returns true
multipleHA.test(A100); // Returns false
timRegex to match the word \"Timber\" only when it has four letter m's."
+ "修改正则表达式 timRegex,以匹配仅有四个字母单词 m 的单词 \"Timber\"。"
],
"tests": [
{
- "text": "Your regex should use curly brackets.",
- "testString": "assert(timRegex.source.match(/{.*?}/).length > 0, 'Your regex should use curly brackets.');"
+ "text": "你的正则表达式应该使用花括号。",
+ "testString": "assert(timRegex.source.match(/{.*?}/).length > 0, '你的正则表达式应该使用花括号。');"
},
{
- "text": "Your regex should not match \"Timber\"",
- "testString": "assert(!timRegex.test(\"Timber\"), 'Your regex should not match \"Timber\"');"
+ "text": "你的正则表达式不应该匹配 \"Timber\"。",
+ "testString": "assert(!timRegex.test(\"Timber\"), '你的正则表达式不应该匹配 \"Timber\"。');"
},
{
- "text": "Your regex should not match \"Timmber\"",
- "testString": "assert(!timRegex.test(\"Timmber\"), 'Your regex should not match \"Timmber\"');"
+ "text": "你的正则表达式不应该匹配 \"Timmber\"。",
+ "testString": "assert(!timRegex.test(\"Timmber\"), '你的正则表达式不应该匹配 \"Timmber\"。');"
},
{
- "text": "Your regex should not match \"Timmmber\"",
- "testString": "assert(!timRegex.test(\"Timmmber\"), 'Your regex should not match \"Timmmber\"');"
+ "text": "你的正则表达式不应该匹配 \"Timmmber\"。",
+ "testString": "assert(!timRegex.test(\"Timmmber\"), '你的正则表达式不应该匹配 \"Timmmber\"。');"
},
{
- "text": "Your regex should match \"Timmmmber\"",
- "testString": "assert(timRegex.test(\"Timmmmber\"), 'Your regex should match \"Timmmmber\"');"
+ "text": "你的正则表达式应该匹配 \"Timmmmber\"。",
+ "testString": "assert(timRegex.test(\"Timmmmber\"), '你的正则表达式应该匹配 \"Timmmmber\"。');"
},
{
- "text": "Your regex should not match \"Timber\" with 30 m\\'s in it.",
- "testString": "assert(!timRegex.test(\"Ti\" + \"m\".repeat(30) + \"ber\"), 'Your regex should not match \"Timber\" with 30 m\\'s in it.');"
+ "text": "你的正则表达式不应该匹配包含 30 个字母 m 的 \"Timber\"。",
+ "testString": "assert(!timRegex.test(\"Ti\" + \"m\".repeat(30) + \"ber\"), '你的正则表达式不应该匹配包含 30 个字母 m 的 \"Timber\"。');"
}
],
"solutions": [],
@@ -1401,7 +1401,7 @@
"name": "index",
"contents": [
"let timStr = \"Timmmmber\";",
- "let timRegex = /change/; // Change this line",
+ "let timRegex = /change/; // 修改这一行",
"let result = timRegex.test(timStr);"
],
"head": [],
@@ -1413,29 +1413,29 @@
"id": "587d7dba367417b2b2512ba8",
"title": "Check for All or None",
"description": [
- "Sometimes the patterns you want to search for may have parts of it that may or may not exist. However, it may be important to check for them nonetheless.",
- "You can specify the possible existence of an element with a question mark, ?. This checks for zero or one of the preceding element. You can think of this symbol as saying the previous element is optional.",
- "For example, there are slight differences in American and British English and you can use the question mark to match both spellings.",
+ "有时,你想要搜寻的匹配模式可能有不确定是否存在的部分。然而,尽管如此,检查它们还是很重要的。",
+ "你可以使用问号 ? 指定可能存在的元素。这将检查前面的零个或一个元素。你可以将此符号视为前面的元素是可选的。",
+ "例如,美式英语和英式英语略有不同,你可以使用问号来匹配两种拼写。",
"let american = \"color\";", "
let british = \"colour\";
let rainbowRegex= /colou?r/;
rainbowRegex.test(american); // Returns true
rainbowRegex.test(british); // Returns true
favRegex to match both the American English (favorite) and the British English (favourite) version of the word."
+ "修改正则表达式 favRegex 以匹配美式英语 (favorite) 和英式英语 (favourite) 的单词版本。"
],
"tests": [
{
- "text": "Your regex should use the optional symbol, ?.",
- "testString": "assert(favRegex.source.match(/\\?/).length > 0, 'Your regex should use the optional symbol, ?.');"
+ "text": "你的正则表达式应该使用可选符号 ?。",
+ "testString": "assert(favRegex.source.match(/\\?/).length > 0, '你的正则表达式应该使用可选符号 ?。');"
},
{
- "text": "Your regex should match \"favorite\"",
- "testString": "assert(favRegex.test(\"favorite\"), 'Your regex should match \"favorite\"');"
+ "text": "你的正则表达式应该匹配 \"favorite\"。",
+ "testString": "assert(favRegex.test(\"favorite\"), '你的正则表达式应该匹配 \"favorite\"。');"
},
{
- "text": "Your regex should match \"favourite\"",
- "testString": "assert(favRegex.test(\"favourite\"), 'Your regex should match \"favourite\"');"
+ "text": "你的正则表达式应该匹配 \"favourite\"。",
+ "testString": "assert(favRegex.test(\"favourite\"), '你的正则表达式应该匹配 \"favourite\"。');"
},
{
- "text": "Your regex should not match \"fav\"",
- "testString": "assert(!favRegex.test(\"fav\"), 'Your regex should not match \"fav\"');"
+ "text": "你的正则表达式不应该匹配 \"fav\"。",
+ "testString": "assert(!favRegex.test(\"fav\"), '你的正则表达式不应该匹配 \"fav\"。');"
}
],
"solutions": [],
@@ -1449,7 +1449,7 @@
"name": "index",
"contents": [
"let favWord = \"favorite\";",
- "let favRegex = /change/; // Change this line",
+ "let favRegex = /change/; // 修改这一行",
"let result = favRegex.test(favWord);"
],
"head": [],
@@ -1461,45 +1461,45 @@
"id": "587d7dba367417b2b2512ba9",
"title": "Positive and Negative Lookahead",
"description": [
- "Lookaheads are patterns that tell JavaScript to look-ahead in your string to check for patterns further along. This can be useful when you want to search for multiple patterns over the same string.",
- "There are two kinds of lookaheads: positive lookahead and negative lookahead.",
- "A positive lookahead will look to make sure the element in the search pattern is there, but won't actually match it. A positive lookahead is used as (?=...) where the ... is the required part that is not matched.",
- "On the other hand, a negative lookahead will look to make sure the element in the search pattern is not there. A negative lookahead is used as (?!...) where the ... is the pattern that you do not want to be there. The rest of the pattern is returned if the negative lookahead part is not present.",
- "Lookaheads are a bit confusing but some examples will help.",
+ "先行断言是告诉 JavaScript 在字符串中向前查找匹配模式的匹配模式。当你想要在同一个字符串上搜寻多个匹配模式时,这可能非常有用。",
+ "有两种先行断言:正向肯定和正向否定。",
+ "正向肯定会查看并确保搜索匹配模式中的元素存在,但实际上并不匹配。正向前置的用法是 (?=...),其中 ... 是必需的部分,尽管不会被匹配。",
+ "另一方面,正向否定会查看并确保搜索匹配模式中的元素不存在。否定前置的用法是 (?!...),其中 ... 是你希望不存在的匹配模式。如果正向否定部分不存在,将返回匹配模式的其余部分。",
+ "尽管先行断言有点儿令人困惑,但是这些示例会有所帮助。",
"let quit = \"qu\";", - "A more practical use of
let noquit = \"qt\";
let quRegex= /q(?=u)/;
let qRegex = /q(?!u)/;
quit.match(quRegex); // Returns [\"q\"]
noquit.match(qRegex); // Returns [\"q\"]
lookaheads is to check two or more patterns in one string. Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:",
+ "先行断言的更实际用途是检查一个字符串中的两个或更多匹配模式。这里有一个简单的密码检查器,它查找 3 到 6 个字符和至少一个数字:",
"let password = \"abc123\";", "
let checkPass = /(?=\\w{3,6})(?=\\D*\\d)/;
checkPass.test(password); // Returns true
lookaheads in the pwRegex to match passwords that are greater than 5 characters long and have two consecutive digits."
+ "在正则表达式 pwRegex 中使用先行断言以匹配长度大于 5 个字符且有两个连续数字的密码。"
],
"tests": [
{
- "text": "Your regex should use two positive lookaheads.",
- "testString": "assert(pwRegex.source.match(/\\(\\?=.*?\\)\\(\\?=.*?\\)/) !== null, 'Your regex should use two positive lookaheads.');"
+ "text": "你的正则表达式应该使用两个肯定先行断言。",
+ "testString": "assert(pwRegex.source.match(/\\(\\?=.*?\\)\\(\\?=.*?\\)/) !== null, '你的正则表达式应该使用两个肯定先行断言。');"
},
{
- "text": "Your regex should not match \"astronaut\"",
- "testString": "assert(!pwRegex.test(\"astronaut\"), 'Your regex should not match \"astronaut\"');"
+ "text": "你的正则表达式不应该匹配 \"astronaut\"。",
+ "testString": "assert(!pwRegex.test(\"astronaut\"), '你的正则表达式不应该匹配 \"astronaut\"。');"
},
{
- "text": "Your regex should not match \"airplanes\"",
- "testString": "assert(!pwRegex.test(\"airplanes\"), 'Your regex should not match \"airplanes\"');"
+ "text": "你的正则表达式不应该匹配 \"airplanes\"。",
+ "testString": "assert(!pwRegex.test(\"airplanes\"), '你的正则表达式不应该匹配 \"airplanes\"。');"
},
{
- "text": "Your regex should match \"bana12\"",
- "testString": "assert(pwRegex.test(\"bana12\"), 'Your regex should match \"bana12\"');"
+ "text": "你的正则表达式应该匹配 \"bana12\"。",
+ "testString": "assert(pwRegex.test(\"bana12\"), '你的正则表达式应该匹配 \"bana12\"。');"
},
{
- "text": "Your regex should match \"abc123\"",
- "testString": "assert(pwRegex.test(\"abc123\"), 'Your regex should match \"abc123\"');"
+ "text": "Your regex should match \"abc123\"。",
+ "testString": "assert(pwRegex.test(\"abc123\"), 'Your regex should match \"abc123\"。');"
},
{
- "text": "Your regex should not match \"123\"",
- "testString": "assert(!pwRegex.test(\"123\"), 'Your regex should not match \"123\"');"
+ "text": "你的正则表达式不应该匹配 \"123\"。",
+ "testString": "assert(!pwRegex.test(\"123\"), '你的正则表达式不应该匹配 \"123\"。');"
},
{
- "text": "Your regex should not match \"1234\"",
- "testString": "assert(!pwRegex.test(\"1234\"), 'Your regex should not match \"1234\"');"
+ "text": "你的正则表达式不应该匹配 \"1234\"。",
+ "testString": "assert(!pwRegex.test(\"1234\"), '你的正则表达式不应该匹配 \"1234\"。');"
}
],
"solutions": [],
@@ -1513,7 +1513,7 @@
"name": "index",
"contents": [
"let sampleWord = \"astronaut\";",
- "let pwRegex = /change/; // Change this line",
+ "let pwRegex = /change/; // 修改这一行",
"let result = pwRegex.test(sampleWord);"
],
"head": [],
@@ -1525,55 +1525,55 @@
"id": "587d7dbb367417b2b2512baa",
"title": "Reuse Patterns Using Capture Groups",
"description": [
- "Some patterns you search for will occur multiple times in a string. It is wasteful to manually repeat that regex. There is a better way to specify when you have multiple repeat substrings in your string.",
- "You can search for repeat substrings using capture groups. Parentheses, ( and ), are used to find repeat substrings. You put the regex of the pattern that will repeat in between the parentheses.",
- "To specify where that repeat string will appear, you use a backslash (\\) and then a number. This number starts at 1 and increases with each additional capture group you use. An example would be \\1 to match the first group.",
- "The example below matches any word that occurs twice separated by a space:",
+ "一些你所搜寻的匹配模式会在字符串中出现多次。手动重复该正则表达式太浪费了。有一种更好的方法可以指定何时在字符串中会有多个重复的子字符串。",
+ "你可以使用捕获组搜寻重复的子字符串。括号 ( 和 ) 被用来匹配重复的子字符串。你只需要把重复匹配模式的正则表达式放在括号中即可。",
+ "要指定重复字符串将出现的位置,可以使用反斜杠(\\)后接一个数字。这个数字从 1 开始,随着你使用的每个捕获组的增加而增加。这里有一个示例,\\1 可以匹配第一个组。",
+ "下面的示例匹配任意两个被空格分割的单词:",
"let repeatStr = \"regex regex\";", - "Using the
let repeatRegex = /(\\w+)\\s\\1/;
repeatRegex.test(repeatStr); // Returns true
repeatStr.match(repeatRegex); // Returns [\"regex regex\", \"regex\"]
.match() method on a string will return an array with the string it matches, along with its capture group.",
+ "在字符串上使用 .match() 方法将返回一个数组,其中包含它匹配的字符串及其捕获组。",
"capture groups in reRegex to match numbers that are repeated only three times in a string, each separated by a space."
+ "在正则表达式 reRegex 中使用捕获组,以匹配在字符串中仅重复三次的数字,每一个都由空格分隔。"
],
"tests": [
{
- "text": "Your regex should use the shorthand character class for digits.",
- "testString": "assert(reRegex.source.match(/\\\\d/), 'Your regex should use the shorthand character class for digits.');"
+ "text": "你的正则表达式应该使用数字的速记字符类。",
+ "testString": "assert(reRegex.source.match(/\\\\d/), '你的正则表达式应该使用数字的速记字符类。');"
},
{
- "text": "Your regex should reuse the capture group twice.",
- "testString": "assert(reRegex.source.match(/\\\\\\d/g).length === 2, 'Your regex should reuse the capture group twice.');"
+ "text": "你的正则表达式应该重用两次捕获组。",
+ "testString": "assert(reRegex.source.match(/\\\\\\d/g).length === 2, '你的正则表达式应该重用两次捕获组。');"
},
{
- "text": "Your regex should have two spaces separating the three numbers.",
- "testString": "assert(reRegex.source.match(/\\\\s/g).length === 2, 'Your regex should have two spaces separating the three numbers.');"
+ "text": "你的正则表达式应该有两个空格分隔这三个数字。",
+ "testString": "assert(reRegex.source.match(/\\\\s/g).length === 2, '你的正则表达式应该有两个空格分隔这三个数字。');"
},
{
- "text": "Your regex should match \"42 42 42\".",
- "testString": "assert(reRegex.test(\"42 42 42\"), 'Your regex should match \"42 42 42\".');"
+ "text": "你的正则表达式应该匹配 \"42 42 42\"。",
+ "testString": "assert(reRegex.test(\"42 42 42\"), '你的正则表达式应该匹配 \"42 42 42\"。');"
},
{
- "text": "Your regex should match \"100 100 100\".",
- "testString": "assert(reRegex.test(\"100 100 100\"), 'Your regex should match \"100 100 100\".');"
+ "text": "你的正则表达式应该匹配 \"100 100 100\"。",
+ "testString": "assert(reRegex.test(\"100 100 100\"), '你的正则表达式应该匹配 \"100 100 100\"。');"
},
{
- "text": "Your regex should not match \"42 42 42 42\".",
- "testString": "assert.equal((\"42 42 42 42\").match(reRegex.source), null, 'Your regex should not match \"42 42 42 42\".');"
+ "text": "你的正则表达式不应该匹配 \"42 42 42 42\"。",
+ "testString": "assert.equal((\"42 42 42 42\").match(reRegex.source), null, '你的正则表达式不应该匹配 \"42 42 42 42\"。');"
},
{
- "text": "Your regex should not match \"42 42\".",
- "testString": "assert.equal((\"42 42\").match(reRegex.source), null, 'Your regex should not match \"42 42\".');"
+ "text": "你的正则表达式不应该匹配 \"42 42\"。",
+ "testString": "assert.equal((\"42 42\").match(reRegex.source), null, '你的正则表达式不应该匹配 \"42 42\"。');"
},
{
- "text": "Your regex should not match \"101 102 103\".",
- "testString": "assert(!reRegex.test(\"101 102 103\"), 'Your regex should not match \"101 102 103\".');"
+ "text": "你的正则表达式不应该匹配 \"101 102 103\"。",
+ "testString": "assert(!reRegex.test(\"101 102 103\"), '你的正则表达式不应该匹配 \"101 102 103\"。');"
},
{
- "text": "Your regex should not match \"1 2 3\".",
- "testString": "assert(!reRegex.test(\"1 2 3\"), 'Your regex should not match \"1 2 3\".');"
+ "text": "你的正则表达式不应该匹配 \"1 2 3\"。",
+ "testString": "assert(!reRegex.test(\"1 2 3\"), '你的正则表达式不应该匹配 \"1 2 3\"。');"
},
{
- "text": "Your regex should match \"10 10 10\".",
- "testString": "assert(reRegex.test(\"10 10 10\"), 'Your regex should match \"10 10 10\".');"
+ "text": "你的正则表达式应该匹配 \"10 10 10\"。",
+ "testString": "assert(reRegex.test(\"10 10 10\"), '你的正则表达式应该匹配 \"10 10 10\"。');"
}
],
"solutions": [],
@@ -1587,7 +1587,7 @@
"name": "index",
"contents": [
"let repeatNum = \"42 42 42\";",
- "let reRegex = /change/; // Change this line",
+ "let reRegex = /change/; // 修改这一行",
"let result = reRegex.test(repeatNum);"
],
"head": [],
@@ -1599,26 +1599,26 @@
"id": "587d7dbb367417b2b2512bab",
"title": "Use Capture Groups to Search and Replace",
"description": [
- "Searching is useful. However, you can make searching even more powerful when it also changes (or replaces) the text you match.",
- "You can search and replace text in a string using .replace() on a string. The inputs for .replace() is first the regex pattern you want to search for. The second parameter is the string to replace the match or a function to do something.",
+ "搜索功能是很有用的。但是,当你的搜索也执行更改(或替换)匹配文本的操作时,会使搜索更加强大。",
+ "可以使用字符串上 .replace() 方法来搜索并替换字符串中的文本。.replace() 的输入首先是你想要搜索的正则表达式匹配模式,第二个参数是用于替换匹配的字符串或用于执行某些操作的函数。",
"let wrongText = \"The sky is silver.\";", - "You can also access capture groups in the replacement string with dollar signs (
let silverRegex = /silver/;
wrongText.replace(silverRegex, \"blue\");
// Returns \"The sky is blue.\"
$).",
+ "你还可以使用美元符号($ code>)访问替换字符串中的捕获组。",
"\"Code Camp\".replace(/(\\w+)\\s(\\w+)/, '$2 $1');
// Returns \"Camp Code\"
",
"
",
- "Write a regex so that it will search for the string \"good\". Then update the replaceText variable to replace \"good\" with \"okey-dokey\"."
+ "编写一个正则表达式,以搜索字符串 \"good\"。然后更新变量 replaceText,用字符串 \"okey-dokey\" 替换 \"good\"。"
],
"tests": [
{
- "text": "You should use .replace() to search and replace.",
- "testString": "assert(code.match(/\\.replace\\(.*\\)/), 'You should use .replace() to search and replace.');"
+ "text": "你应该使用 .replace() 搜索并替换。",
+ "testString": "assert(code.match(/\\.replace\\(.*\\)/), '你应该使用 .replace() 搜索并替换。');"
},
{
- "text": "Your regex should change \"This sandwich is good.\" to \"This sandwich is okey-dokey.\"",
- "testString": "assert(result == \"This sandwich is okey-dokey.\" && replaceText === \"okey-dokey\", 'Your regex should change \"This sandwich is good.\" to \"This sandwich is okey-dokey.\"');"
+ "text": "你的正则表达式应该把 \"This sandwich is good.\" 变成 \"This sandwich is okey-dokey.\"。",
+ "testString": "assert(result == \"This sandwich is okey-dokey.\" && replaceText === \"okey-dokey\", '你的正则表达式应该把 \"This sandwich is good.\" 变成 \"This sandwich is okey-dokey.\"。');"
},
{
- "text": "You should not change the last line.",
- "testString": "assert(code.match(/result\\s*=\\s*huhText\\.replace\\(.*?\\)/), 'You should not change the last line.');"
+ "text": "你不应该改变最后一行。",
+ "testString": "assert(code.match(/result\\s*=\\s*huhText\\.replace\\(.*?\\)/), '你不应该改变最后一行。');"
}
],
"solutions": [],
@@ -1632,8 +1632,8 @@
"name": "index",
"contents": [
"let huhText = \"This sandwich is good.\";",
- "let fixRegex = /change/; // Change this line",
- "let replaceText = \"\"; // Change this line",
+ "let fixRegex = /change/; // 修改这一行",
+ "let replaceText = \"\"; // 修改这一行",
"let result = huhText.replace(fixRegex, replaceText);"
],
"head": [],
@@ -1645,23 +1645,23 @@
"id": "587d7dbb367417b2b2512bac",
"title": "Remove Whitespace from Start and End",
"description": [
- "Sometimes whitespace characters around strings are not wanted but are there. Typical processing of strings is to remove the whitespace at the start and end of it.",
+ "有时字符串周围存在的的空白字符并不是必需的。字符串的典型处理是删除字符串开头和结尾处的空格。",
"
",
- "Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.",
- "Note
The .trim() method would work here, but you'll need to complete this challenge using regular expressions."
+ "编写一个正则表达式并使用适当的字符串方法删除字符串开头和结尾的空格。",
+ "注意
.trim() 方法在这里也是起作用的,但是你需要使用正则表达式来完成此项挑战。"
],
"tests": [
{
- "text": "result should equal to \"Hello, World!\"",
- "testString": "assert(result == \"Hello, World!\", 'result should equal to \"Hello, World!\"');"
+ "text": "结果应该等于 \"Hello, World!\"。",
+ "testString": "assert(result == \"Hello, World!\", '结果应该等于 \"Hello, World!\"。');"
},
{
- "text": "You should not use the .trim() method.",
- "testString": "assert(!code.match(/\\.trim\\(.*?\\)/), 'You should not use the .trim() method.');"
+ "text": "你不应该使用 .trim() 方法。",
+ "testString": "assert(!code.match(/\\.trim\\(.*?\\)/), '你不应该使用 .trim() 方法。');"
},
{
- "text": "The result variable should not be set equal to a string.",
- "testString": "assert(!code.match(/result\\s*=\\s*\".*?\"/), 'The result variable should not be set equal to a string.');"
+ "text": "结果变量不应该设置为等于字符串。",
+ "testString": "assert(!code.match(/result\\s*=\\s*\".*?\"/), '结果变量不应该设置为等于字符串。');"
}
],
"solutions": [],
@@ -1677,8 +1677,8 @@
"name": "index",
"contents": [
"let hello = \" Hello, World! \";",
- "let wsRegex = /change/; // Change this line",
- "let result = hello; // Change this line"
+ "let wsRegex = /change/; // 修改这一行",
+ "let result = hello; // 修改这一行"
],
"head": [],
"tail": []
@@ -1686,4 +1686,4 @@
}
}
]
-}
\ No newline at end of file
+}
diff --git a/02-javascript-algorithms-and-data-structures/regular-expressions.md b/02-javascript-algorithms-and-data-structures/regular-expressions.md
index 9289429..aed9755 100644
--- a/02-javascript-algorithms-and-data-structures/regular-expressions.md
+++ b/02-javascript-algorithms-and-data-structures/regular-expressions.md
@@ -1,3 +1,69 @@
-# Introduction to the Regular Expression Challenges #
+# 正则表达式挑战简介 #
-Regular expressions are special strings that represent a search pattern. Also known as "regex" or "regexp", they help programmers match, search, and replace text. Regular expressions can appear cryptic because a few characters have special meaning. The goal is to combine the symbols and text into a pattern that matches what you want, but only what you want. This section will cover the characters, a few shortcuts, and the common uses for writing regular expressions.
+正则表达式是表示搜索模式的特殊字符串。也被称为“regex”或“regexp”,它们可以帮助程序员匹配、搜索和替换文本。由于一些字符具有特殊的含义,正则表达式可能会显得晦涩难懂。我们的目标是将这些符号和文本组合成一个你想要的匹配模式,但这只是你想要的。本节将介绍字符、一些快捷方式以及编写正则表达式的常用用法。
+
+# 课程目录 #
+
+使用 test 方法
+
+匹配文字字符串
+
+匹配各种不同的文字字符串
+
+匹配时忽略大小写
+
+提取匹配项
+
+不只是第一次匹配
+
+通配符匹配一切
+
+匹配各种不同的单个字符
+
+匹配字母表中的字母
+
+匹配数字和字母表中的字母
+
+匹配未指定的单个字符
+
+匹配出现一次或多次的字符
+
+匹配出现零次或多次的字符
+
+使用懒惰匹配查找字符
+
+在追捕中找到一个或多个罪犯
+
+开始字符串模式匹配
+
+结尾字符串模式匹配
+
+匹配所有的字母和数字
+
+匹配除了字母和数字之外的一切
+
+匹配所有的数字
+
+匹配所有的非数字
+
+限制可能的用户名
+
+匹配空白字符
+
+匹配非空白字符
+
+指定匹配的上限和下限
+
+只指定匹配的下限
+
+指定匹配的确切数量
+
+匹配全部或不匹配
+
+正向肯定和正向否定断言
+
+使用捕获组重用匹配模式
+
+使用捕获组搜索并替换
+
+去掉首尾的空白字符