2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d7db8367417b2b2512ba1
|
|
|
|
|
title: Match All Non-Numbers
|
|
|
|
|
challengeType: 1
|
|
|
|
|
videoUrl: ''
|
|
|
|
|
localeTitle: 匹配所有非数字
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
<section id="description">最后一项挑战显示了如何使用带有小写<code>d</code>的快捷键<code>\d</code>来搜索数字。您也可以使用类似的使用大写<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(noNumRegex.source));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 你的正则表达式应该使用全局标志。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(noNumRegex.global);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 你的正则表达式应该在<code>"9"</code>找不到非数字。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert("9".match(noNumRegex) == null);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 你的正则表达式应该在<code>"Catch 22"</code>找到6个非数字。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert("Catch 22".match(noNumRegex).length == 6);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 你的正则表达式应该在<code>"101 Dalmatians"</code>找到11个非数字。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert("101 Dalmatians".match(noNumRegex).length == 11);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '你的正则表达式应该在<code>"One, Two, Three"</code>找到15个非数字。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert("One, Two, Three".match(noNumRegex).length == 15);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: 你的正则表达式应该在<code>"21 Jump Street"</code>找到12个非数字。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert("21 Jump Street".match(noNumRegex).length == 12);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
- text: '你的正则表达式应该在<code>"2001: A Space Odyssey"</code>找到17个非数字。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: 'assert("2001: A Space Odyssey".match(noNumRegex).length == 17);'
|
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 noNumRegex = /change/; // Change this line
|
|
|
|
|
let result = numString.match(noNumRegex).length;
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
|
|
|
|
</section>
|