Hello @rachad-antonius, @claudia-frank, @Scott-sumner, and All,
Claudia, don’t forget that the \s regular syntax matches any single character of the range [\t\n\x0B\f\r\x20\x85\xA0\x{2028}\x{2029}]
So let’s imagine this initial text, below :
Which begins with 3 empty lines
With 2 other empty lines, after line bbbbbbb
And the second to last line contains, ONLY the expression GIVEN_WORD
GIVEN_WORD aaaaaaaaaaaa
bbbbbbb
GIVEN_WORD ccccccccc
GIVEN_WORDeeeeeeeeeeeeeeeee
GIVEN_WORD fffffff
gggggggggggggggggg
hhhhhhhhh
GIVEN_WORD iiiiiiiiiiiiiiiiiiiiiiiiiiiii
GIVEN_WORD
jjjjjjjjjjjjjjjjjjjjjj
With your regex, ^\s*GIVEN_WORD.*, this text turns into :
bbbbbbb
gggggggggggggggggg
hhhhhhhhh
jjjjjjjjjjjjjjjjjjjjjj
Whereas the Scott’s regex, (?-s)^GIVEN_WORD.*\R gives :
bbbbbbb
gggggggggggggggggg
hhhhhhhhh
jjjjjjjjjjjjjjjjjjjjjj
This later syntax seems more correct as it matches a single line, at a time ;-)) doesn’t it ? Claudia, you may click several times on the couple Find Next | Replace, with the View > Show Symbol > Show All Characters option set !
BTW, @rachad-antonius, the \R syntax, at the end of the regex, matches the line-break characters of the current line, whatever the kind of file ( Unix, Windows, or Mac ) !
Additional Notes :
In case, @rachad-antonius, that you would like, in addition, to delete entire lines, having some blank characters ( spaces and/or tabulations ), before the GIVEN_WORD, you could use the regex ^\h*GIVEN_WORD(?-s).*\R
Secondly , depending if you prefer the GIVEN_WORD to be matched with that exact case, or not, you could choose :
The regex ^\h*(?-i)GIVEN_WORD(?-s).*\R for an exact case match
The regex ^\h*(?i)GIVEN_WORD(?-s).*\R for a match, independent of the case of GIVEN_WORD
Finally, if GIVEN_WORD represents an complete expression, containing special regex characters, I advice you to use the following one : ^\h*(?-i)\QGIVEN_WORD\E(?-s).*\R. Indeed, between the 2 syntaxes \Q and \E, you may insert any character or symbol, without no restriction !!
Refer to :
http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html#boost_regex.syntax.perl_syntax.quoting_escape
For instance, if you want to delete the entire lines, beginning with the string +++ | Test | +++, whatever the case of the word test, and possibly preceded, in the same line, by some blank characters, use the regex, below :
^\h*(?i)\Q+++ | Test | +++\E(?-s).*\R
Remark :
If you don’t use the quoted form \Q.......\E, the regex must be rewritten as below, which each special regex character escaped with an \ character !
^\h*(?i)\+\+\+ \| Test \| \+\+\+(?-s).*\R
Best Regards,
guy038
P. S. :
Claudia, many Thanks for your Xmas Greetings ! Sorry for not replying, in time :-< I just forgot to consult my e-mail box ;-))