2020-10-06 23:10:08 +05:30

1.8 KiB

id, challengeType, forumTopicId, title
id challengeType forumTopicId title
587d7db5367417b2b2512b97 1 301356 匹配字母表中的数字和字母

Description

使用连字符(-)匹配字符范围并不仅限于字母。它还可以匹配一系列数字。 例如,/[0-5]/匹配05之间的任意数字,包含05。 此外,还可以在单个字符集中组合一系列字母和数字。
let jennyStr = "Jenny8675309";
let myRegex = /[a-z0-9]/ig;
// matches all letters and numbers in jennyStr
jennyStr.match(myRegex);

Instructions

创建一个正则表达式,使其可以匹配hs之间的一系列字母,以及26之间的一系列数字。请记得在正则表达式中包含恰当的标志。

Tests

tests:
  - text: 你的正则表达式<code>myRegex</code>应该匹配 17 项。
    testString: assert(result.length == 17);
  - text: 你的正则表达式<code>myRegex</code>应该使用全局标志。
    testString: assert(myRegex.flags.match(/g/).length == 1);
  - text: 你的正则表达式<code>myRegex</code>应该使用忽略大小写的标志。
    testString: assert(myRegex.flags.match(/i/).length == 1);

Challenge Seed

let quoteSample = "Blueberry 3.141592653s are delicious.";
let myRegex = /change/; // Change this line
let result = myRegex; // Change this line

Solution

let quoteSample = "Blueberry 3.141592653s are delicious.";
let myRegex = /[h-s2-6]/gi; // Change this line
let result = quoteSample.match(myRegex); // Change this line