[Issue 9390] New: Option for verbose regular expressions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 24 18:14:04 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9390
Summary: Option for verbose regular expressions
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-01-24 18:14:01 PST ---
I'd really like an option to write "verbose" regular expressions in D, like in
Python:
http://docs.python.org/2/library/re.html
> re.X
> re.VERBOSE
>
> This flag allows you to write regular expressions that look
> nicer. Whitespace within the pattern is ignored, except when in a
> character class or preceded by an unescaped backslash, and, when
> a line contains a '#' neither in a character class or preceded by
> an unescaped backslash, all characters from the leftmost such '#'
> through the end of the line are ignored.
>
> That means that the two following regular expression objects that
> match a decimal number are functionally equal:
>
> a = re.compile(r"""\d + # the integral part
> \. # the decimal point
> \d * # some fractional digits""", re.X)
> b = re.compile(r"\d+\.\d*")
RE code is code like every other, so it enjoys comments, a nicer indenting and
formatting.
Making RE more readable helps their debug and understand. In my Python code all
RE longer than half a line of chars are "verbose".
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list