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