[pcre-dev] [Bug 1679] New: Ability to explicitly specify wha…

Kezdőlap
Üzenet törlése
Szerző: admin
Dátum:  
Címzett: pcre-dev
Tárgy: [pcre-dev] [Bug 1679] New: Ability to explicitly specify what to capture (feature request)
https://bugs.exim.org/show_bug.cgi?id=1679

            Bug ID: 1679
           Summary: Ability to explicitly specify what to capture (feature
                    request)
           Product: PCRE
           Version: N/A
          Hardware: All
                OS: All
            Status: NEW
          Severity: wishlist
          Priority: medium
         Component: Code
          Assignee: ph10@???
          Reporter: henrik.hank@???
                CC: pcre-dev@???


Hello,

it would be very helpful to be able to explicitly specify what the group being
in should capture. You should be able to specify original and other capture
strings when specifying what to capture for a group. The modified capture
string would be available for the replacement string. I'm unsure whether
following groups in the regular expression should see the original or the
modified capture string.

This feature is useful when doing find-and-replace according to a list--let me
put it like this--with two columns. I.e., replace A with B, C with D and E with
F. How else would you want to accomplish this than speciying the replacements
in the regular expression? So, I think, it's appropriate.

I tried to use existing features with Perl--with semi-satisfying results. This
Perl script does the job:
> print (("apple, cherry, lemon" =~ s/
>         \bapple\b
>         (*MARK:pear)
>     |
>         \bcherry\b
>         (*MARK:strawberry)
>     |
>         \blemon\b
>         (*MARK:lime)
>     /$REGMARK/xgr) . "\n");

Output:
> pear, strawberry, lime

This also works:
> print (("a1a" =~ s/
>         \d
>         (*MARK:()
>     /$REGMARK/xgr) . "\n");

This doesn't work:
> print (("a1a" =~ s/
>         \d
>         (*MARK:\))
>     /$REGMARK/xgr) . "\n");



POSSIBLE SYNTAX

Subject string:
> apple, cherry, lemon

Regular expression with replacement syntax:
> (?x)
>     \bapple\b
>     (*CAPTURE:
>         $0\ \(pear\)
>     )
> |
>     \bcherry\b
>     (*CAPTURE:
>         $0\ \(strawberry\)
>     )
> |
>     \blemon\b
>     (*CAPTURE:
>         $0\ \(lime\)
>     )

Regular expression with consistent syntax:
> (?x)
>     \bapple\b
>     (*CAPTURE:
>         \g{0}\ \(pear\)
>     )
> |
>     \bcherry\b
>     (*CAPTURE:
>         \g{0}\ \(strawberry\)
>     )
> |
>     \blemon\b
>     (*CAPTURE:
>         \g{0}\ \(lime\)
>     )

Replacement string:
> $0

Result:
> apple (pear), cherry (strawberry), lemon (lime)



Are there any doubts/objections/contradictions?

--
You are receiving this mail because:
You are on the CC list for the bug.