|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2003-11-19 12:09:21
At 12:19 AM 11/18/2003, Joel de Guzman wrote:
>Eric Niebler <eric_at_[hidden]> wrote:
>> Brian McNamara wrote:
>>
>>> I agree that it is desirable to be able to _statically_ (at
>>> compile-time) analyze and "compute on" regexps.
>>>
>>> The main disadvantage is that it forces us to write regexps "ugly":
>>>
>>> +(_1 = "hello ") >> "world"
>>>
>>> rather than "pretty":
>>>
>>> regexp("(hello )+world")
>>
>> Some would say regular expressions are ugly any way you look at them.
>> :-) As an expression template, you can use whitespace, indenting and
>> comments to make your regular expression more readable. Beauty is in
the
>> eye of coder.
>
>Same here. I dislike REs a lot. It gives me a mild headache whenever I
have
>to read understand one. "(hello )+world" is ok--It's the more complex
stuff
>that gives me an eye strain. For instance, from the regex manual:
> "\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z". I really hate
>those escapes. I also hate the fact that you can't format the code and
>sprinkle it with whitespace. The ugliness of the RE syntax is one of the
>motivating forces that made me write Spirit.
While I agree with you about the escapes, it really isn't correct that "you
can't format the code and sprinkle it with whitespace".
To take your example:
"\\A(\\d{3,4})[- ]" // first group comment
"?(\\d{4})[- ]" // second group comment
"?(\\d{4})[- ]" // third group comment
"?(\\d{4})\\z" // fourth and final group comment
C++'s adjacent string concatenation rule (2.13.4/3) is very helpful in
making any long string literal more readable. Not just RE's.
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk