3.0 KiB
3.0 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db8367417b2b2512ba3 | Match Whitespace | 1 | تطابق الفراغ |
Description
\s
، وهي صغيرة s
. لا يطابق هذا النمط المسافة البيضاء فحسب ، بل يطابق أيضًا أحرف الإرجاع ، وعلامة التبويب ، وتغذية النموذج ، وأحرف الخطوط الجديدة. يمكنك اعتباره مشابهًا لفئة الأحرف [ \r\t\f\n\v]
. let whiteSpace = "Whitespace. Whitespace everywhere!"
اترك spaceRegex = / \ s / g؛
whiteSpace.match (spaceRegex)؛
// عائدات [" "، " "]
Instructions
countWhiteSpace
regex للبحث عن أحرف بيضاء متعددة في سلسلة. Tests
tests:
- text: يجب أن يستخدم تعبيرك العادي العلم العام.
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
- text: يجب أن يستخدم تعبيرك العادي الحرف المختصر
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
- text: يجب أن يعثر تعبيرك المعتاد على ثماني مساحات في <code>"Men are from Mars and women are from Venus."</code>
testString: 'assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, "Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: 'يجب أن يعثر تعبيرك المعتاد على ثلاث مسافات في <code>"Space: the final frontier."</code>'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, "Your regex should find three spaces in <code>"Space: the final frontier."</code>");'
- text: يجب ألا يجد <code>"MindYourPersonalSpace"</code> أي مسافات في <code>"MindYourPersonalSpace"</code>
testString: 'assert("MindYourPersonalSpace".match(countWhiteSpace) == null, "Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>");'
Challenge Seed
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);
Solution
// solution required