Bug 12367 – std.regex: Recognize (?# ... ) comment syntax

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-14T17:11:00Z
Last change time
2016-04-11T15:23:33Z
Assigned to
dmitry.olsh
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2014-03-14T17:11:29Z
A comment syntax would be handy for particularly long expressions. This syntax seems to be already supported by several existing engines: http://www.regular-expressions.info/freespacing.html#parenscomment
Comment #1 by bearophile_hugs — 2014-03-14T17:21:08Z
(In reply to comment #0) > A comment syntax would be handy for particularly long expressions. > > This syntax seems to be already supported by several existing engines: > http://www.regular-expressions.info/freespacing.html#parenscomment While it's good to have a basic (?# ... ) comment syntax, I much prefer the Python verbose regex syntax, because it allows me to lay down regexes as little programs, with logically indented lines and #-style comments: http://docs.python.org/2/library/re.html http://www.diveintopython.net/regular_expressions/verbose.html >>> pattern = """ ^ # beginning of string M{0,4} # thousands - 0 to 4 M's (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's), # or 500-800 (D, followed by 0 to 3 C's) (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's), # or 50-80 (L, followed by 0 to 3 X's) (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), # or 5-8 (V, followed by 0 to 3 I's) $ # end of string """
Comment #2 by github-bugzilla — 2016-04-11T15:23:33Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/12c7d680449dde70fdb5f35c997d6940e4298a81 Fix issue 12367 - std.regex: Recognize (?# ... ) comment syntax https://github.com/D-Programming-Language/phobos/commit/9f256889edd5069fe6d3e6babb22c406933dbd2c Add documnetation and changelog for issue 12367 https://github.com/D-Programming-Language/phobos/commit/b4f0478434ba3c44306f9cfaf74d250e481fca32 Merge pull request #4159 from DmitryOlshansky/issue-12367 Fix issue 12367 - std.regex: Recognize (?# ... ) comment syntax