help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple regexp replace in not working


From: Xah Lee
Subject: Re: Simple regexp replace in not working
Date: Sun, 6 May 2012 13:27:52 -0700 (PDT)
User-agent: G2/1.0

On May 6, 8:06 am, ld1976 <lior_da...@yahoo.com> wrote:
> Hello all.
> I have file with the following two lines (for example):
>
>                 qp = ~masterp ;
>                 qn = ~mastern ;
>
> I want to change them to :
>                 #0.05 qp = ~masterp ;
>                 #0.05 qn = ~mastern ;
> What that I do is enter the following regexp:
> Replace regexp is: \([^ ]+[ ]+=\)
> And the with field is: #0.05 \1
> I get the following mess:
>                 Qp = ~masterp #0.05 ;
>                 qn = ~mastern ;
> My version is 21.4.1, LINUX. File is 
> attached.http://old.nabble.com/file/p33763498/not_working.emacsnot_working.emacs
>
> --
> View this message in 
> context:http://old.nabble.com/Simple-regexp-replace-in-not-working-tp33763498...
> Sent from the Emacs - Help mailing list archive at Nabble.com.


in your case, best to just call string-rectangle instead.

but if using regex, your regex has a few problems.

> Replace regexp is: \([^ ]+[ ]+=\)

The 「[^ ]+」 there is greedy. It'll grab as much as possible. You want
a non-greedy one: 「[^ ]+?」.

Also, you want a line beginning anchor 「^」. Or, actually put newline
in your regex. (type it by 【Ctrl+q Ctrl+j】)

here's what i'd use:

「q\(.\) = ~master\(.\) ;」
「#0.05 q\1 = ~master\2 ;」

 Xah


reply via email to

[Prev in Thread] Current Thread [Next in Thread]