Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10294
    vinc25
    Member

    I have test.txt with lines:

    test 1
    test 2

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

    Result:

    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??? :-?

    #10295
    Stefan
    Participant

    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.

    #10296
    vinc25
    Member

    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.

    #10297
    Stefan
    Participant

    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.

    .

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.