Find a string using Regular Expression, Store the result and use it in another search as replace with text
-
Looking to Find string using RegularExpression like
FindWhat: - *name.lqr" and
if a string found of this RegEx pattern then store the value of found string in a variable or somewhere else
so that this stored value can be used in next FindReplace as a ReplaceWith value.Example: -
First Find with Regular Expression: -
*name.lqr"Suppose, by this we found a string -> name_exam_test_ratio_lqr" Then need to temporarily save this string either in a variable or somewhere else for another Find&Replace.
Now, need to do Find&Replace with Regular Expression only for another expression in Find like: -
Find What: - .*mov"
Replace With: - <The String found in “First Find” i.e. name_exam_test_ratio_lqr"Please advice: -
1) Any way to achieve this in Notepad++ via Find&Replace &
2) Can we have this in Macro also?Thanks!
-
-
Thanks Alen for speedy response … Could you please advice which script is supported in Notepad++ and how to achive this please…Thanks!
-
@B-Sethi24 said in Find a string using Regular Expression, Store the result and use it in another search as replace with text:
Could you please advice
Well, I’d go with Pythonscript (it’s a Notepad++ plugin).
Let me throw together a quick demo; if needed you could then build upon it yourself. -
Here’s a real quick demo:
# -*- coding: utf-8 -*- from Npp import editor, notepad def demo(): user_input = notepad.prompt('First expr:', '', 'foo') matches = [] editor.research(user_input, lambda m: matches.append(m.span(0)), 0, 0, editor.getLength(), 1) if len(matches): first_match_text = editor.getTextRange(matches[0][0], matches[0][1]) user_input = notepad.prompt('Second expr:', '', 'bar') editor.rereplace(user_input, first_match_text, 0, 0, editor.getLength(), 1) demo()
-
Additionally, here are some basic instructions for installing Pythonscript and getting a script to run:
And here’s some stuff about binding the execution of a script to a keycombo: