multiple text replacing with different text
-
@Handa-Flocka said in multiple text replacing with different text:
it does not change anything
Can you tell me the exact steps you took, because it works for me.
-
… for example, here’s a screen-capture video:
-
Now it works like a charm!! I forgot some steps during the process
both of them now are working perfectly
it would be preferred to use python script instead of regex in this process if I am dealing with huge data?Thank you for your help so much appreciation man
-
@Handa-Flocka said in multiple text replacing with different text:
it would be preferred to use python script instead of regex in this process if I am dealing with huge data?
Correct. Large amounts of data will mean that the
(.*?~+\s*)
capture groups grows beyond the regex capture-group memory allocated in Notepad++. -
got it!
Thank you and for the effort you put on this -
I am replying to your Chat message here. Questions like this belong in the Forum posts, not in the chat.
Sorry If bothering you
I have tried again to run the same py script on some random code it didn’t want to change
codeEVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift
for example I am selecting word
TYPEE
it doesn’t change at allMy guess is that the chat window got rid of the <open> tags on most of those. But the example included
TYPEE
, and that’s likely all that’s critical for the replacement.- Change
replaceList.py
sokeywordText = 'TYPEE'
; SAVE - Open file with example text
EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift
- Plugins > PythonScript > Scripts >
replaceList
- Result
… SoEVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“CANADA” MODIFIERS=shift
TYPEE
has becomeCANADA
So it works for me.
- Change
-
@PeterJones said in multiple text replacing with different text:
EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift
@PeterJones my bad I thought the thread was locked!
the code works perfectly in one line
but If I tried something like this for exampleEVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift
then it will not work!
-
@Handa-Flocka said in multiple text replacing with different text:
then it will not work!
Sorry, I don’t know what you’re doing differently. With no change compared to my sequence above (that is, with
TYPEE
as the keyword and the same list of three countries as the replacementList), I get:EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“CANADA” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“MEXICO” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“COSTA RICA” MODIFIERS=shift EVENTS TYPE=keypress SELECTOR=“body>div.page_wrap>div.im_page_wrap.clearfix>div>div.im_history_col_wrap.noselect.im_history_loaded>div.im_history_selected_wrap>div>div.im_bottom_panel_wrap>div.im_send_panel_wrap.noselect>div>div>div>form>div.im_send_field_wrap.hasselect>div.composer_rich_textarea” CHARS=“TYPEE” MODIFIERS=shift
Since my list only had 3 countries, the fourth
TYPEE
remains unchanged.Here is my exact
replaceList.py
with your data:# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/21225/ Written by @PeterJones Searches for the value of keywordText multiple times, and replaces it with the next element of replacementList """ from Npp import * keywordText = 'TYPEE' replacementList = [ 'CANADA', 'MEXICO', 'COSTA RICA' ] counter = -1 def nextReplacement(m): global counter counter += 1 return replacementList[counter] if counter < len(replacementList) else m.group(0) editor.beginUndoAction() editor.replace(keywordText, nextReplacement) editor.endUndoAction()
You might want to go to Plugins > PythonScript > Show Console and look for errors. (You can right click in the console window, click Clear, then run the script again on your data file. If anything is printed in the console, it’s an error message.) The error message will likely indicate where you have a typo or syntax error in the script that was introduced when you put in your new
keywordText
andreplacementList
. If you need help with that, copy/paste the errors you see into the forum (as well as your modified copy ofreplaceList.py
) -
This post is deleted! -
This post is deleted! -
@PeterJones After your update it’s a piece of art now!
thanks again