RegEx selective replace
-
Hi
I’m hoping someone can help as I’ve been struggling with this all day!
I have some text files that I want to do some search/replace on but I can’t work out how to reference selectively what I’m trying to replace.
Taking this as the test:
IF Thirty THEN DRAW(" Twenty, Thirty, Forty, Fifty") ENDIFI would like to replace the Thirty on line that includes DRAW with ‘30’ but not on the IF line. How can I do this please.
I’m tearing my hair out!
Many thanks
Rob
-
- FIND WHAT =
(?-s)(DRAW.*)Thirty - REPLACE WITH =
$1Replacement - MODE = regular expression
Requires
DRAWto come before theThirty, on the same line.(?-s)= dot wildcard does not match space(DRAW.*)= literal textDRAWfollowed by 0 or more characters (.*), all put into group#1Thirty= literal text you want to replace$1= in the replacement, this will include the contents of group#1, which is everything fromDRAW(including theDRAW) to just before theThirtyReplacement= the word you want to insert instead ofThirty
-—
Official Notepad++ Searching/Regex Docs = https://npp-user-manual.org/docs/searching/#regular-expressions - FIND WHAT =
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login