How do I add a specific text at the end of each line start with same specific text



  • Hi,

    I have something like this
    FLEXGRP_BA01
    FLEXGRP_CN08
    FLEXGRP_CR8765
    FLEXGRP_ZN760

    and replace with this

    FLEXGRP_BA01_FLEXGRP
    FLEXGRP_CN08_FLEXGRP
    FLEXGRP_CR8765_FLEXGRP
    FLEXGRP_ZN760_FLEXGRP

    I have tried using syntax below but it doesn’t work
    Find: (?-si)^FLEXGRP_.+
    Replace with: $0_FLEXGRP

    Your help would be greatly appreciated. Thank you!



  • @Khoa-Le

    You are actually amazingly close.
    Simply put braces around your 0 in your replacement, i.e., ${0}



  • @Khoa-Le ,

    Thank you for the before and after data, and showing what you tried. That’s appreciated.

    Unfortunately, when I try what you showed, it worked for me.

    00b46dc3-7232-4858-b6d2-8a2812e2365c-image.png

    @Alan-Kilborn – his worked for me without edits, without the braces. Though I agree that braces are a better idea, to avoid problems.

    FLEXGRP_BA01
    FLEXGRP_CN08
    FLEXGRP_CR8765
    FLEXGRP_ZN760
    

    became

    FLEXGRP_BA01_FLEXGRP
    FLEXGRP_CN08_FLEXGRP
    FLEXGRP_CR8765_FLEXGRP
    FLEXGRP_ZN760_FLEXGRP
    

    You’re already following most of the advice below, but I’m showing it because </> would help make sure there isn’t a forum-special character in your data (like I showed above)… and it’s a good reminder for everyone

    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.



  • @PeterJones said in How do I add a specific text at the end of each line start with same specific text:

    his worked for me without edits, without the braces. Though I agree that braces are a better idea, to avoid problems.

    Ha. I didn’t even try the original replacement string.
    It isn’t often that we get a request where someone actually has it right at the time of asking!

    I thought there was something special about 0, and you’re right, I just always err on the side of caution and do ${0}, ${1}, etc. I guess the special thing I’m thinking of about 0 is that you can’t do \0 like you can \1, \2, etc.

    Aside: Most people like the \1 notation because it is shorter than ${1} but I like the cleaner look of the latter, and “leaning toothpicks” make me crazy as well.


Log in to reply