[Issue 7260] "g" on default in std.regex

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 10 10:43:33 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7260



--- Comment #6 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2013-03-10 10:43:30 PDT ---
(In reply to comment #4)
> If changing std.regex.regex is not possible, then an alternative solution is to
> introduce the new little function "std.regex.re", that repeats on default, that
> is like:
> 
> re(someString) === regex(someString, "g")
> 
> re(someString, "d") === regex(someString, "dg")

Here is a plan based on one of my previous idea that I think is clean enough,
given the circumstances and the fact that e.g. this Perl-ism is fairly popular
in certain circles. 

(Namely attaching mode of operation to the pattern itself as in
/`pattern`/`mode-suffix`).

What we do is at first specify that "g" serves only as the intended default
"mode" of this pattern. 

Then introduce simple and elegant way to explicitly specify what mode of
matching to use: first, all or the default for this pattern.

The your code looks like this (I'm still pondering better names/ways for
overriding default):

void main() {
    string text = "abc312de";

    foreach (c; text.match("1|2|3|4").first)
        write(c, " ");
    writeln();

    foreach (c; text.match(regex("1|2|3|4")).all) //could use string pattern as
above
        write(c, " ");
    writeln();
}

Then I'd try to do the same with replace. 
No overrides used would imply "use whatever the default mode is". 

How does it sound? 

Then we place nice bold warning that use of "g" option is discouraged and is
provided only for compatibilty and is going be deprecated in future.

A year later and depending on the mood of people it gets finally deprecated and
slowly shifted towards oblivion.

I'll probably cross-post this to NG to collect opinions since this is the
largest pain point of the otherwise fine interface.

-- 
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