Skip to content

Recommend using + for token part of parsing regex - #750

Open
RobertCochran wants to merge 1 commit into
kanaka:masterfrom
RobertCochran:guide-recommend-plus-regex
Open

RobertCochran wants to merge 1 commit into
kanaka:masterfrom
RobertCochran:guide-recommend-plus-regex

Conversation

@RobertCochran

Copy link
Copy Markdown

The old token parsing regex used * to match non-special tokens, which would occasionally match and add empty string to the token stream. Change to + to fix this.

Addresses #503 on the guide side; does not change any implementations.

Comment thread process/guide.md
Comment on lines +355 to +359
NOTE: Some simplistic regular expression engines may not support the `+`
(match one or more) operator. If your language's regular expression engine
is one such implementation, then you may need to substitute the `+` for `*`
(match zero or more) and filter out empty tokens from the input stream
manually.

@RobertCochran RobertCochran Nov 30, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kanaka asks in #503 to add a blurb about working around deficient regex implementations that don't have +, so I did so. I'm not exactly happy that there's no further guidance than 'it might not work ¯\_(ツ)_/¯'. What are some known-problematic implementations? How can an implementer tell they've managed to stumble on one?

Comment thread process/guide.md
* ```[\[\]{}()'`~^@]```: Captures any special single character, one of
```[]{}()'`~^@``` (tokenized).

* `"(?:\\.|[^\\"])*"?`: Starts capturing at a double-quote and stops at the

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string-parsing segment of the regex uses a PCRE non-capture group to group parts of the string parsing part of the regex together without creating another capture entry. Shouldn't we also say something about working around this if needed? IMO, it is far more likely that a more simplistic regex package wouldn't support non-capture groups than the + operator.

Comment thread process/guide.md
Comment on lines 327 to 328
of all the tokens (strings) in it. The following regular expression
(PCRE) will match all mal tokens.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We explicitly say that this regex is PCRE but then provide advice for how to work around an implementation that doesn't support +? A regex engine that claims to be PCRE that doesn't support + is just broken.

Perhaps instead we should say something along the lines of 'if your engine does not support PCRE, then you can adapt this regex with <list of possible problem spots and their solutions>'. That will probably clue in a potential implementer better that they are (perhaps inadvertently) wandering off the beaten path and either inspire them to be sure their regex engine really is PCRE or will need to take more care in using a regex to parse in their implementation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant