-
Notifications
You must be signed in to change notification settings - Fork 4
Supported Modifier Flags #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For the examples, can you share how you'd do it without the relevant proposal? |
|
There's nothing with |
I'm not sure I understand what you mean. Can you clarify? |
If you mean using |
I just want to share a little trick to emulate - /^ $/ == /(?<![\s\S]) (?![\s\S])/
- /^ $/m == /(?<!.) (?!.)/ // no `s` flag! This works for both |
The modifiers supported by this proposal will be limited to |
@rbuckton, I know this is already closed (and implemented in V8, yay!), but for interest's sake, note that it's very possible to emulate presence or lack of
Emulating is possible without
It's easier than that:
Note that, like your |
Or |
FWIW: In the example “Match a frontmatter block at the start of a file” work, line terminators have to be consumed. This works for me: const re = /(?-m:^)---\r?\n((?:^(?!---$).*\r?\n)*)^---$/m;
assert.equal(re.test('---a'), false);
assert.equal(re.test('---\n---'), true);
assert.equal(
re.exec('---\n---')[1],
''
);
assert.equal(
re.exec('---\na: b\n---')[1],
'a: b\n'
); |
In the Oct, 2021 plenary, @michaelficarra asked that we outline and provide motivating examples for each flag we are considering as a supported modifier.
The flags currently under consideration are:
i
— ignore-caseD
followed by word starting withD
ord
(from .NET documentation, see 1)m
— multilines
— dot-all (i.e., "single line").
matching semantics within a pattern.x
— Extended Mode. This flag is proposed by https://github.com/tc39/proposal-regexp-x-modex
mode when composing a complex pattern:Flags likely too complex to support:
u
— Unicode. This flag affects how a pattern is parsed, not how it is matched. Supporting it would likely require a cover grammar and additional static semantics.v
— Extended Unicode. This flag is proposed by https://github.com/tc39/proposal-regexp-set-notation as an extension of theu
flag and would have the same difficulties.Flags that will never be supported:
g
— Global. This flag affects the index at which matching starts and not the matching behavior itself. Changing it mid pattern would have no effect.y
— Sticky. This flag affects the index at which matching starts and not the matching behavior itself. Changing it mid pattern would have no effect.d
— Indices. This flag affects the match result. Changing it mid pattern would have no effect.Footnotes
https://docs.microsoft.com/en-us/dotnet/standard/base-types/miscellaneous-constructs-in-regular-expressions#inline-options ↩
The text was updated successfully, but these errors were encountered: