-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Issue #1 points out that there is a grammar controlling regular expression parsing that will require some odd restrictions on even the comments included in the regular expression if we go through with this proposal as it is.
I also noticed that even if this proposal goes through as it is currently defined, the resulting multi-line-with-comments regular expressions you would write would be almost identical in size and readability to regular expressions generated with my example utility function below. Also, when using this utility function there is no need for odd restrictions on the content of comments.
function assembleRegExp(array, flags = undefined) {
return new RegExp(array.join(''), flags);
}
let wordIntPairRe = assembleRegExp(
[
// match from the beginning, but allow leading spaces
'^\\s*',
// word captured to a group named "word"
'(?<word>[a-zA-Z]+)',
// at least one whitespace
'\\s+',
// integer captured to a group named "int"
'(?<int>[0-9]+)',
// allow trailing whitespace, but nothing else
'\\s*$',
]);
console.log(wordIntPairRe);
console.log(wordIntPairRe.exec(' abc 123 '));
So, perhaps rather than proposing an 'x' flag in order to get comments, this proposal should define a method similar to the above?
Metadata
Metadata
Assignees
Labels
No labels