1.4 KiB
1.4 KiB
id, challengeType, forumTopicId, title
id | challengeType | forumTopicId | title |
---|---|---|---|
587d7dbb367417b2b2512bac | 1 | 301362 | 删除开头和结尾的空白 |
Description
Instructions
.trim()
方法在这里也可以实现同样的效果,但是你需要使用正则表达式来完成此项挑战。
Tests
tests:
- text: "<code>结果</code>应该等于<code>'Hello, World!'</code>。"
testString: assert(result == "Hello, World!");
- text: 你不应该使用<code>.trim()</code>方法。
testString: assert(!code.match(/\.trim\(.*?\)/));
- text: <code>结果</code>变量不应该设置为等于字符串。
testString: assert(!code.match(/result\s*=\s*".*?"/));
Challenge Seed
let hello = " Hello, World! ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line
Solution
let hello = " Hello, World! ";
let wsRegex = /^(\s+)(.+[^\s])(\s+)$/;
let result = hello.replace(wsRegex, '$2');