- AuthorPosts
- April 27, 2012 at 6:06 pm #10294vinc25Member
I have test.txt with lines:
test 1
test 2I use FIND en REPLACE WITH:
FIND = ^(.+?)$
RECPLACE WITH = $1 = $1Result:
test 1 = test 1
test 2 = test 2My problem:
I want the result “test 1 = test+1”. How can I replace a string in the placeholder??? :-?April 28, 2012 at 8:02 am #10295StefanParticipantThat’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.April 28, 2012 at 11:38 am #10296vinc25MemberThank 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.
April 28, 2012 at 1:22 pm #10297StefanParticipantThis 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..
- AuthorPosts
- You must be logged in to reply to this topic.