Hello,
This is a summary of ruby-dev mailing list for last week.
[ruby-dev:19953] Re: How do we parse Regular Expressions in our brain?
This thread has been started from [ruby-dev:19923] as a branch of
Oniguruma thread. TAKAHASHI Masayoshi and Akira Tanaka are investigating
rules to escape ‘[’, ‘]’ and ‘-’ characters in regexp for legibility.
They plan to change the regexp parsing rule in 1.8.0 as follows so far.
The plan is based on regexp coding conventions and requests from others
in ruby-dev:
-
‘[’ and ‘]’ must be escaped by ‘’ when they appear as a literal
in character class expressions. /[[]]/ should be coded as /[[]]/
for example. -
A literal ‘-’ in a character class should be escaped too if the
class has other ‘-’ literals for range representation. For instance,
/[abcd-f-hijk]/ and /[–abc]/ should be written as
/[abcd-f-hijk]/ (or /[abcd-f-hijk]/) and /[–abc]/.
You can use ‘-’ without ‘’ if the class has no ranges, like
/[-abc]/ or /[^-]/. -
A literal ‘]’ at outside of character classes will be warned
if it has no escape character such like /a]/. It should be
changed to /a]/.
Regexp parser will warn for them in 1.8.0.
Kazuo Saito ksaito@uranus.dti.ne.jp