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_ZN760and replace with this
FLEXGRP_BA01_FLEXGRP
FLEXGRP_CN08_FLEXGRP
FLEXGRP_CR8765_FLEXGRP
FLEXGRP_ZN760_FLEXGRPI have tried using syntax below but it doesn’t work
Find: (?-si)^FLEXGRP_.+
Replace with: $0_FLEXGRPYour help would be greatly appreciated. Thank you!
-
You are actually amazingly close.
Simply put braces around your0
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.
@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 usingCtrl+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 about0
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.