\s
، باستخدام s
صغير. يمكنك أيضًا البحث عن كل شيء ما عدا المسافة البيضاء. البحث عن غير بيضاء، يستخدم \S
، وهي الأحرف الكبيرة s
. لن يطابق هذا النمط المسافات البيضاء ، والعودة إلى السطر ، وعلامة التبويب ، وتغذية النموذج ، وأحرف الخطوط الجديدة. يمكنك التفكير في كونه مشابهًا لفئة الأحرف [^ \r\t\f\n\v]
. let whiteSpace = "Whitespace. Whitespace everywhere!"
اترك nonSpaceRegex = / \ S / g؛
whiteSpace.match (nonSpaceRegex) مدة العرض. // إرجاع 32
countNonWhiteSpace
regex للبحث عن أحرف non-whitespace متعددة في سلسلة. \S/code> to match all non-whitespace characters.");'
- text: يجب أن يعثر تعبيرك المعتاد على 35 حالة غير مسافات في "Men are from Mars and women are from Venus."
testString: 'assert("Men are from Mars and women are from Venus.".match(countNonWhiteSpace).length == 35, "Your regex should find 35 non-spaces in "Men are from Mars and women are from Venus."
");'
- text: 'يجب أن يعثر تعبيرك المعتاد على 23 منطقة غير مسافات في "Space: the final frontier."
'
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23, "Your regex should find 23 non-spaces in "Space: the final frontier."
");'
- text: يجب أن يعثر "MindYourPersonalSpace"
على 21 "MindYourPersonalSpace"
غير مسافات في "MindYourPersonalSpace"
testString: 'assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21, "Your regex should find 21 non-spaces in "MindYourPersonalSpace"
");'
```