Forever-Young / mrab-regex-hg

Automatically exported from code.google.com/p/mrab-regex-hg
0 stars 0 forks source link

reconsider case-changing controls in replacement? #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to propose an addition for the casechanging syntax in regex 
replacements as considered in 
http://bugs.python.org/issue2636#msg83988

Given many of the features mentioned in that older context are already 
implemented now, the added complexity of the syntax doesn't seem like a problem 
any more (at least from the user's point of view, of course).

I believe, this sort of straightforward string manipulation would be handled 
more naturally in the replacement pattern directly; while the replacement 
function (already available now for this) is better for more complex 
conversions, possibly with further lookups on other "grammar" or "dictionary" 
data etc.
Unless I miss something, probably \U\g<1> and \L\g<1> would be sufficient for 
case conversions of whole groups, while \u\g<1> and \l\g<1> could be achieved 
by adding an  explicit group for the first character (also reducing the issue 
with l vs. 1).

It seems, that the enhancement would be unambiguous, although there would be 
context-dependent similar patterns; however, unicode escapes require some 
following hex numbers, and named list are only meaningful in search patterns 
and not in the replacements.

Of course, this is meant just as an suggestion; if the implementation burden 
would be inappropriate, or if there were some other problems, it is certainly 
no fundamental feature, just a handy shortcut.

(P.S.: Many thanks for implementing the enhanced error cost syntax in the fuzzy 
matches, ...{0<e<3} is certainly much handier, than the equivalent lookarounds 
I used earlier.)

Thanks and regards,
     vbr

Original issue reported on code.google.com by Vlastimil.Brom@gmail.com on 29 Jan 2012 at 2:58

GoogleCodeExporter commented 9 years ago
I did ask for opinions about this some time ago. The response was negative, and 
my feeling is that they were probably right.

I know that Perl has it, but I don't know of any other regex implementation 
which does. It's probably unPythonic! :-)

Original comment by re...@mrabarnett.plus.com on 8 Feb 2012 at 3:23

GoogleCodeExporter commented 9 years ago
Fair enough, thanks for the response; it would indeed be nothing more than a 
convenience shortcut and you are likely right, that it wouldn't be worth it. 
Previously, I found some docs on that feature besides perl, but I am not sure, 
whether these tools don't use some variants of perl regex engine...
http://vimregex.com/#backreferences
http://lists.gnu.org/archive/html/help-gnu-emacs/2007-04/msg00431.html
http://manual.macromates.com/en/regular_expressions#case_foldings

besides this, there is an extended syntax (on top of PCRE) in a special editor 
I use: Classical Text Editor, here it is spelled eg:
${1:u}
(first group uppercased)

But well, it is a marginal case.
 regards,
   vbr

Original comment by Vlastimil.Brom@gmail.com on 8 Feb 2012 at 11:27