freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities.chinese.md
Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

3.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7db4367417b2b2512b90 Match a Literal String with Different Possibilities 1 匹配具有不同可能性的文字字符串

Description

使用/coding/等正则表达式,可以在另一个字符串中查找"coding"模式。这对搜索单个字符串很有用,但它仅限于一种模式。您可以使用alternationOR运算符搜索多个模式: | 。此运算符在其之前或之后匹配模式。例如,如果你想匹配"yes""no" ,你想要的正则表达式是/yes|no/ 。您还可以搜索两种以上的模式。您可以通过添加更多模式来实现此操作,其中更多OR运算符将它们分开,例如/yes|no|maybe/

Instructions

完成正则表达式petRegex以匹配宠物"dog" "cat" "bird""fish"

Tests

tests:
  - text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;John has a pet dog.&quot;</code>返回<code>true</code> <code>&quot;John has a pet dog.&quot;</code>
    testString: assert(petRegex.test('John has a pet dog.'));
  - text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;Emma has a pet rock.&quot;</code>返回<code>false</code> <code>&quot;Emma has a pet rock.&quot;</code>
    testString: assert(!petRegex.test('Emma has a pet rock.'));
  - text: 你的正则表达式<code>petRegex</code>应该为字符串<code>&quot;Emma has a pet bird.&quot;</code>返回<code>true</code> <code>&quot;Emma has a pet bird.&quot;</code>
    testString: assert(petRegex.test('Emma has a pet bird.'));
  - text: 你的正则表达式<code>petRegex</code>应该返回<code>true</code>为字符串<code>&quot;Liz has a pet cat.&quot;</code>
    testString: assert(petRegex.test('Liz has a pet cat.'));
  - text: 你的正则表达式<code>petRegex</code>应该返回<code>false</code>为<code>&quot;Kara has a pet dolphin.&quot;</code>的字符串<code>&quot;Kara has a pet dolphin.&quot;</code>
    testString: assert(!petRegex.test('Kara has a pet dolphin.'));
  - text: 你的正则表达式<code>petRegex</code>应该返回<code>true</code>为字符串<code>&quot;Alice has a pet fish.&quot;</code>
    testString: assert(petRegex.test('Alice has a pet fish.'));
  - text: 你的正则表达式<code>petRegex</code>应该返回<code>false</code>为字符串<code>&quot;Jimmy has a pet computer.&quot;</code>
    testString: assert(!petRegex.test('Jimmy has a pet computer.'));

Challenge Seed

let petString = "James has a pet cat.";
let petRegex = /change/; // Change this line
let result = petRegex.test(petString);

Solution

// solution required