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