impatient-js icon indicating copy to clipboard operation
impatient-js copied to clipboard

Chapter: Regular expressions (`RegExp`)

Open rauschma opened this issue 5 years ago • 10 comments

rauschma avatar Jan 02 '19 17:01 rauschma

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.

VernonHawk avatar May 24 '19 20:05 VernonHawk

No, “is” is correct: If you don’t provide flags then the copy has the same flags as the original.

rauschma avatar May 25 '19 09:05 rauschma

Oh, ok, I misunderstood the meaning of the sentence, sorry.

VernonHawk avatar May 25 '19 13:05 VernonHawk

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.

anthemion-org avatar Nov 17 '19 22:11 anthemion-org

40.3 Flags

/g (.global): fundamentally changes how the following methods work.

Maybe it is worth to add String.prototype.replace() to the list?

vsemozhetbyt avatar Aug 17 '20 17:08 vsemozhetbyt

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..."?

vsemozhetbyt avatar Aug 18 '20 16:08 vsemozhetbyt

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 "#".

vsemozhetbyt avatar Aug 18 '20 16:08 vsemozhetbyt

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 avatar Mar 17 '21 02:03 davidmaxwaterman

@davidmaxwaterman True, thanks! Fixed in next release.

rauschma avatar Jan 02 '22 12:01 rauschma

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!

leodeslf avatar Jul 02 '22 01:07 leodeslf