How to use the character being replaced in the replacement text again

2013-06-29
2013-06-29
  • Rahul Rusia

    Rahul Rusia - 2013-06-29

    How to use the character being replaced in the replacement text again?
    For eg - in the text -> a's id is 12, b's id is 13, c's id is 14
    I then want to get person's name and id and replace it as a=12, b-13, c-14, likewise.
    Is it possible with notepad++?
    It would be great help, if anybody could come up with a solution of it, if possible?

     
  • THEVENOT Guy

    THEVENOT Guy - 2013-06-29

    Hello Rahul Rusia,

    I didn't understand exactly which kind of S/R you're looking for ! But conditional replacements, in regular expression search mode, may interest you !

    So, if you use the 6.0 version of N++ or a newer version, and if the Regular expression search mode is SET :

    SEARCH : (Word1)|(Word2)|(Word3)|...|(Wordn)

    REPLACE : (?1WordA)(?2WordB)(?3WordC)...(?nWordX)

    Then a mouse click on the Replace All button change, in the current file :

    • ANY occurrence of Word1 into the expression WordA
    • ANY occurrence of Word2 into the expression WordB
    • ANY occurrence of Word3 into the expression WordC

    ..........................................

    • ANY occurrence of Wordn into the expression WordX

    So, this kind of S/R allow you to do more than one S/R, at the same time !

    For example :

    SEARCH : ( €)|(S/R)|(Regexp?) with a space before the Euro sign

    REPLACE : (?1 Euro)(?2Search/Replacement)(?3\3 Pattern) with a space before the words Euro and Pattern )

    will replace the subject string :

    This S/R, with the search Regexp = ".*€$", will select all the lines, ending with the symbol €.

    by the sentence :

    This Search/Replacement, with the search Regexp Pattern = ".*€$", will select all the lines, ending with the symbol Euro.

    Notes :

    • Any string " €" is replaced with the string " Euro"
    • Any string S/R is replaced with the string "Search/Replacement"
    • Any string "Regex" or "Regexp" is replaced with the search string ( \3), followed by the string " Pattern"

    Hope this specific S/R can be useful to you ?!

    Cheers,

    guy038

     
    Last edit: THEVENOT Guy 2013-06-29
  • Rahul Rusia

    Rahul Rusia - 2013-06-29

    hey thanks for the support you provided, with a great details but what I have with myself is huge amount of data with each line containing a word(different for different lines), also the word in each line is different but we know the actual occurence of that segment is after few fixed words.

    For eg - X Y Z REPLACEMENT Y H J

    here x y z and y h j are fixed but the word replacement is different for different lines.

    I want to replace above line as NEW WORD = REPLACEMENT.

    And the data is large, i was thinking if notepad++ could support such needs?

     
  • THEVENOT Guy

    THEVENOT Guy - 2013-06-29

    Hi Rahul Rusia,

    I'm sorry but I don't exactly see what you want to achieve, yet. Do you mean that the lines :

    X Y Z Word_to_Replace1 Y H J
    X Y Z Word_to_Replace2 Y H J
    X Y Z Word_to_Replace3 Y H J
    ........................
    X Y Z Word_to_Replacen Y H J

    have to be changed into :

    X Y Z NEW WORD = Word_to_Replace1 Y H J
    X Y Z NEW WORD = Word_to_Replace2 Y H J
    X Y Z NEW WORD = Word_to_Replace3 Y H J
    ...................................
    X Y Z NEW WORD = Word_to_Replacen Y H J

    I don't think that I understood your needs because this kind of S/R seems obvious : Just change the word Z by the literal string Z NEW WORD =, as the word Z is known and doesn't change !

    May be, I won't answer you immediately because it's about 11.00 p.m., in France and I need to get up at 5.00am tomorrow. So, I would rather go to bed, right now !

    Cheers,

    Guy038

     
    Last edit: THEVENOT Guy 2013-06-29

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks