Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
103 lines (68 loc) · 3.98 KB

File metadata and controls

103 lines (68 loc) · 3.98 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#coding=utf-8
import re
# --------------------------------------------------------------------------------------------------------------------------------------
# Script "Multiples_SR.py"
# A LITTLE adaptation by guy038 from an ORIGINAL and VALUABLE script of Alan KILBORN ( January 2019 ) !
# See https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/21
# and https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/23
# This script :
# - Reads an existing "SR_List.txt" file, of the CURRENT directory, containing a list of SEARCH/REPLACEMENT strings, ONE PER line
# - Selects, one at a time, a COUPLE of SEARCH and REPLACEMENT regexes / expressions / strings / characters
# - Executes this present S/R on CURRENT edited file, in NOTEPAD++
# - Loop till the END of file
# Any PURE BLANK line or COMMENT line, beginning with '#', of the "SR_list.txt" file, are simply IGNORED
# --------------------------------------------------------------------------------------------------------------------------------------
# For EACH line, in the "SR_List.txt" file, the format is <DELIMITER><SEARCH regex><DELIMITER><REPLACE regex><DELIMITER>
## EXAMPLES :
## ¯¯¯¯¯¯¯¯
## Deletes any [ending] "; comment" / Delimiter = '!'
#!(?-s)(^.*?);.+!\1!
## Changes any LOWER-case string "notepad++" in its UPPER-case equivalent / Delimiter = '@'
#@(?-i)notepad\+\+@NOTEPAD++@
## Changes any "Smith" and 'James' strings, with that EXACT case, to, respectively, "Name" and "First name" / Delimiter = '&'
## Deletes any "TEST" string, with that EXACT case
#&(Smith)|TEST|(James)&(?1Name)(?2First name)&
## Replaces any BACKSLASH character with the "123" number, both preceded and followed with 3 SPACE characters / Delimiter = '%'
#%\\% 123 %
## or, also, the syntax %\x5c% 123 %
## Deletes any string "Fix", followed with a SPACE char, whatever its CASE / Delimiter = '+'
#+(?i)Fix ++
## Change 3 CONSECUTIVE "#" characters with 3 BACKSLASH characters / Delimiter = '*'
#*###*\\\\\\*
# --------------------------------------------------------------------------------------------------------------------------------------
# In the CODE line, right below, you may :
# - Modify the NAME of the file, containing the SEARCH and REPLACEMENT regexes
# - Indicate an ABSOLUTE or RELATIVE path, before the filename
with open(r'SR_list.txt') as f: sr_list = f.readlines()
# You may, as well, insert the SEARCH and REPLACE regexes, directly, in THIS script :
#sr_list = [
# '!(?-s)(^.*?);.+!\\1!',
# '@(?-i)notepad\\+\\+@NOTEPAD++@',
# '&(Smith)|TEST|(James)&(?1Name)(?2First name)&',
# '%\\\\% 123 %',
# # or the syntax '%\x5c\x5c% 123 %',
# '+(?i)Fix ++',
# '*###*\\\\\\\\\\\\*',
# ]
# The use of RAW strings r'.......' is also possible, in order to SIMPLIFY some regexes
# Note that these RAW regexes are strictly IDENTICAL to those, which could be contained in a "SR_List.txt" file, WITHOUT the 'r' PREFIX
#sr_list = [
# r'!(?-s)(^.*?);.+!\1!',
# r'@(?-i)notepad\+\+@NOTEPAD++@',
# r'&(Smith)|TEST|(James)&(?1Name)(?2First name)&',
# r'%\\% 123 %',
# # or the syntax r'%\x5c% 123 %',
# r'+(?i)Fix ++',
# r'*###*\\\\\\*',
# ]
editor.beginUndoAction()
console.write ('\nMODIFICATIONS on FILE "{}: "\n\n'.format(notepad.getCurrentFilename()))
# Note : Variable e is always EMPTY string ( Part AFTER the THIRD delimiter and BEFORE the END of line ! )
for line in sr_list:
if line[0] == '#' or line == '\n' : continue
(s,r,e) = line[1:].rstrip('\n').split(line[0])
console.write(' SEARCH : >{}<\n'.format(s))
console.write(' REPLACE : >{}<\n\n'.format(r))
editor.rereplace(s,r) # or editor.rereplace(s,r,re.IGNORECASE) / editor.rereplace(s,r,re.I)
editor.endUndoAction()
# END of Multiple_SR.py script
Morty Proxy This is a proxified and sanitized view of the page, visit original site.