impatient-js
impatient-js copied to clipboard
Chapter: Regular expressions (`RegExp`)
39.1.2. Cloning and non-destructively modifying regular expressions
...
new RegExp(regExp : RegExp, flags = regExp.flags) [ES6]
regExp
is cloned. If flags
is provided then it determines the flags of the copy.
Probably should be isn't provided.
No, “is” is correct: If you don’t provide flags
then the copy has the same flags as the original.
Oh, ok, I misunderstood the meaning of the sentence, sorry.
I'm looking at section 40.3. According to MDN, the 'a' in dotall
should be capitalized: dotAll
. Testing with NodeJS 10.16.3 confirms this. Same problem in the print edition.
40.3 Flags
/g (.global): fundamentally changes how the following methods work.
Maybe it is worth to add String.prototype.replace()
to the list?
40.5.9 Other methods for working with regular expressions
Its first parameter of String.prototype.split() is either a string or a regular expression.
Seems a bit off. Maybe "The first parameter of..." or "Its first parameter is..."?
40.6.5 Summary: .global (/g) and .sticky (/y)
Two tables use one legend with "Column “#”" explanation, but the first table has "Calls" column header instead of "#".
https://exploringjs.com/impatient-js/ch_regexps.html#replace-replaceAll
The table heading has "RegExp w/o \g" (backslash) which should probably be '/g' as in other instances.
@davidmaxwaterman True, thanks! Fixed in next release.
Hi!
I'd like to mention something that's not wrong, but, I think can actually lead to a misunderstanding about the exec
method from RegExp
.
Under the title 43.6.4.1 Getting a match object for the first match, it says:
Without the flag
/g
,.exec()
returns ...
Which suggests that with the flag /g
, .exec()
returns something else, but it's not the case (maybe it worked differently before, or maybe I'm missing something).
console.log(/(a+)b/.exec('ab aab'));
// --> [ 'ab', 'a', index: 0, input: 'ab aab', groups: undefined ]
console.log(/(a+)b/g.exec('ab aab'));
// --> [ 'ab', 'a', index: 0, input: 'ab aab', groups: undefined ]
Wouldn't it be better to say that .exec()
"ignores" the flag /g
?
Cheers!