I have a long text document that has over 24,000 lines. I need to search through for 83 different words and remove all instances of these 83 words when the words occur alone on a line (see example below). The Words will be removed. But the search must ignore:
§
symbol (regardless if the rest of the line has capital or lower case letters).Example
§History of TIME
HISTORY OF TIME
of
Future
Past
Of
Many Of
Official
Officer
North of the town
I am one of them
If I search for Of
then in the above only the third and sixth line would be highlighted.
The first line would not be highlighted because it begins with a §
.
The second line would not be highlighted because it is in all caps.
Many of
, North of the town
, and I am one of them
would not be highlighted, because it is not Of
on its own.
Is this possible in Sublime? I think searching for all 83 separate words would make the query too complicated. But if I can search for one word at a time (ensuring it skips all lines that are in Caps and all lines that begin with a §
, then that would be okay).
If this is not possible in Sublime, is there any other method I can use?
You say you want to remove all occurrences of of
when a line does not start with a §
or is ALLCAPS and when not part of a many of
, north of
, one of
, etc. phrase.
Use
Find: (^(?:(?:§.*|[^[:alpha:]\n\r]*[[:upper:]]+(?:[^[:alpha:]\n\r]+[[:upper:]]+)*[^[:alpha:]\n\r]*))$|(?i:\b(?:many|north|one)\s+of\b))|(?i:\bof\b)
Replace: $1
See regex demo
Details
(^(?:(?:§.*|[^[:alpha:]\n\r]*[[:upper:]]+(?:[^[:alpha:]\n\r]+[[:upper:]]+)*[^[:alpha:]\n\r]*))$|(?i:\b(?:many|north|one)\s+of\b))
- Capturing group 1 (referred to with $1
placeholder from the replacement pattern):
^
- start of a line(?:
- a group:
§.*
|
- or[^[:alpha:]\n\r]*[[:upper:]]+(?:[^[:alpha:]\n\r]+[[:upper:]]+)*[^[:alpha:]\n\r]*
- 0+ chars other than LF/CR symbols and letters, then 1+ uppercase letters, then 0+ sequences of non-linebreak and non-letter chars followed with 1+ uppercase letters and ending with 0+ sequences of non-linebreak and non-letter chars)$
- end|
or
(?i:\b(?:many|north|one)\s+of\b)
- a case insensitive group matching many
, north
or one
followed with 1+ whitespaces and then of
as whole words|
- or (?i:\bof\b)
- a case insensitive group: of
as a whole word.See the SublimeText3 test, mind to select regex mode and case sensitive matching: