[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: query-replace-regexp on a string with '=' sign
From: |
Tassilo Horn |
Subject: |
Re: query-replace-regexp on a string with '=' sign |
Date: |
Fri, 09 Sep 2022 07:10:22 +0200 |
User-agent: |
mu4e 1.9.0; emacs 29.0.50 |
Pankaj Jangid <pankaj@codeisgreat.org> writes:
>>> I have a line like this,
>>> HELLO=WORLD
>>> now I want to downcase the part before the equal (=) sign.
>>> I am approaching like this
>>>
>>> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET
>>>
>>> But this doesn't work.
>>
>> Where "doesn't work" means "doesn't downcase but keeps HELLO", right?
>
> Yes. Suppose I have these lines in a region
> HELLO=WORLD
> HELLOXXXXWORLD
> and if I now execute following sequence,
> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET
> the output is,
>
> hello=WORLD
> HELLOXXXXWORLD
For me (with emacs -Q on the current master), it stays as it is, i.e.,
all caps.
> but if I execute this,
> M-x query-replace-regexp RET \(.+\)XXXX RET \,(downcase \1)XXXX RET
> then the output is,
>
> HELLO=WORLD
> helloXXXXWORLD
I can reproduce that. I think that's documented on the info page I've
cited. When the replacement is all lower- or all uppercase (like
hello=), `case-replace' has an effect. But when the replacement is
mixed-case (like helloXXXX), case will be preserved.
>> Have a look at (info "(emacs) Replacement and Lax Matches") which
>> explains it. I think the default `case-replace' value of t is the
>> problem here.
>
> Thanks for pointing me to the right direction. Understood case-replace
> thing. But the one thing that is still not clear to me is that, why
> the first command doesn't downcase HELLO in the first line, whereas
> the second command downcases the HELLO in the second line.
Huh? You've said the first command does downcase hello in the first
line although I cannot reproduce that and would not have an explanation
for that behavior. If it's actually the same for you, then see my last
paragraph for the explanation.
Bye,
Tassilo
- query-replace-regexp on a string with '=' sign, Pankaj Jangid, 2022/09/08
- Re: query-replace-regexp on a string with '=' sign, Tassilo Horn, 2022/09/08
- Re: query-replace-regexp on a string with '=' sign, Pankaj Jangid, 2022/09/09
- Re: query-replace-regexp on a string with '=' sign,
Tassilo Horn <=
- Re: query-replace-regexp on a string with '=' sign, Pankaj Jangid, 2022/09/09
- Re: query-replace-regexp on a string with '=' sign, Tassilo Horn, 2022/09/09
- Re: query-replace-regexp on a string with '=' sign, Pankaj Jangid, 2022/09/09
- Re: query-replace-regexp on a string with '=' sign, Tassilo Horn, 2022/09/09
- Re: query-replace-regexp on a string with '=' sign, Pankaj Jangid, 2022/09/10
Re: query-replace-regexp on a string with '=' sign, Emanuel Berg, 2022/09/16
Re: query-replace-regexp on a string with '=' sign, Emanuel Berg, 2022/09/16