EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     replace string in placeholder ($1)?
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
Stefan
Posted on: 4/28/2012 5:22 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 258
Re: replace string in placeholder ($1)?
This is how i see it. Don't know if i am 100% correct.


\n

"\n" are RegEx METACHARs from the old UNIX days with his SED and GREP tools.

"\1" e.g. will give back what is matched by the expression
enclosed in the first set of parentheses (counted from the left)


"\n" are used for a backreference within an search pattern.
E.g. to match double chars like "(.)\1" to match "support".
That way the search pattern is extended by the way
with the match of the expression to find it two times.


"\n" can also be used to refer to an match in the find
AFTER it is done, for an use in the replacement like
Find: "(\d)" Replace: "the number is \1"


$n

"$n" OTOH was introduced by Perl and is an VARIABLE
which holds the match of an expression after the find is done.
"$n" can be seen here as an synonym of "\n". But only in the replacement.



Recapitulation

This days it seems to depend of the used regex engine (or maybe on the coder of the app?)
which flavor is used to represents an backreference
in the REPLACEMENT: \1 or $1 can be used.

But for the backreference in the SEARCH string i think always \1 is used.


It seams EmEditor (using the Boost library) does the same.
\1 is allowed in the FIND only (no $1 here)
but \1 AND $1 are both allowed in the replacement field.



.
vinc25
Posted on: 4/28/2012 3:38 am
Just popping in
Joined: 8/7/2010
From:
Posts: 3
Re: replace string in placeholder ($1)?
Thank you. Using 2 or more capture groups works. It only takes more code to get the same result.

By the way...What is the differents between $1 and \1. I get the same result for both.
Stefan
Posted on: 4/28/2012 12:02 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 258
Re: replace string in placeholder ($1)?

That's not possible. You have to change your how-to.

Use a more granular expression to capture the text and the digit into two separate capture groups.
Then you have the possibilities on the replacement as you want.
vinc25
Posted on: 4/27/2012 10:06 am
Just popping in
Joined: 8/7/2010
From:
Posts: 3
replace string in placeholder ($1)?
I have test.txt with lines:
Quote:

test 1
test 2


I use FIND en REPLACE WITH:
FIND = ^(.+?)$
RECPLACE WITH = $1 = $1

Result:
Quote:

test 1 = test 1
test 2 = test 2


My problem:
I want the result "test 1 = test+1". How can I replace a string in the placeholder???
Threaded | Oldest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文