freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../regular-expressions/specify-upper-and-lower-num...

2.8 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7db9367417b2b2512ba5 Specify Upper and Lower Number of Matches 1 指定上下匹配数

Description

回想一下,您使用加号+来查找一个或多个字符,使用星号*来查找零个或多个字符。这些很方便,但有时你想要匹配一定范围的模式。您可以使用quantity specifiers模式的下限和上限。数量说明符与大括号( {} )一起使用。您在大括号之间放置了两个数字 - 用于较低和较高的模式数。例如,为了匹配字母"ah"出现35次的字母a ,你的正则表达式将是/a{3,5}h/
让A4 =“aaaah”;
让A2 =“aah”;
令multipleA = / a {3,5} h /;
multipleA.testA4; //返回true
multipleA.testA2; //返回false

Instructions

更改正则表达式ohRegex以匹配单词"Oh no"中的36字母h

Tests

tests:
  - text: 你的正则表达式应该使用大括号。
    testString: 'assert(ohRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
  - text: 你的正则表达式不应该匹配<code>&quot;Ohh no&quot;</code>
    testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match <code>"Ohh no"</code>");'
  - text: 你的正则表达式应该匹配<code>&quot;Ohhh no&quot;</code>
    testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match <code>"Ohhh no"</code>");'
  - text: 你的正则表达式应该匹配<code>&quot;Ohhhh no&quot;</code>
    testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match <code>"Ohhhh no"</code>");'
  - text: 你的正则表达式应该匹配<code>&quot;Ohhhhh no&quot;</code>
    testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match <code>"Ohhhhh no"</code>");'
  - text: 你的正则表达式应该匹配<code>&quot;Ohhhhhh no&quot;</code>
    testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match <code>"Ohhhhhh no"</code>");'
  - text: 你的正则表达式不应该匹配<code>&quot;Ohhhhhhh no&quot;</code>
    testString: 'assert(!ohRegex.test("Ohhhhhhh no"), "Your regex should not match <code>"Ohhhhhhh no"</code>");'

Challenge Seed

let ohStr = "Ohhh no";
let ohRegex = /change/; // Change this line
let result = ohRegex.test(ohStr);

Solution

// solution required