Skip to content

Commit f028b8d

Browse files
authored
Update whitespace documentation
Signed-off-by: yuvi-mittal <[email protected]>
1 parent 7f76495 commit f028b8d

File tree

1 file changed

+20
-0
lines changed
  • lib/node_modules/@stdlib/regexp/whitespace

1 file changed

+20
-0
lines changed

lib/node_modules/@stdlib/regexp/whitespace/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ var out = replace( str, reWhitespace.REGEXP_CAPTURE, '$1$1' );
111111

112112
- Matches one related white space character without the Unicode character property "WSpace=Y" (zero width non-breaking space which was deprecated as of Unicode 3.2).
113113

114+
- Unlike the \s shorthand in JavaScript, @stdlib/regexp/whitespace explicitly targets Unicode 9.0 white space characters, ensuring consistency and compatibility across environments.
115+
The predefined \s shorthand relies on the ECMAScript specification and may vary slightly in behavior, especially in older or less compliant environments.
116+
Example demostrating difference
117+
```javascript
118+
var testString = 'Hello\u200BWorld';
119+
120+
var regex = /\s/;
121+
console.log(regex.test(testString)); // returns true in some engines(ES5 or older)
122+
123+
var reWhitespace = require( '@stdlib/regexp/whitespace' );
124+
var RE_WHITESPACE = reWhitespace();
125+
console.log(RE_WHITESPACE.test(testString)); // returns false
126+
127+
var arr = testString.split(regex);
128+
console.log(arr); // ["Hello", "World"]
129+
130+
arr = testString.split(RE_WHITESPACE);
131+
console.log(arr); // ["Hello\u200BWorld"]
132+
```
133+
114134
- The `REGEXP` regular expression is defined as
115135

116136
```text

0 commit comments

Comments
 (0)