I'm trying to make a regex that deletes the first and the last 10 lines of my 200 txt files with "Search and Replace all"
I tried (\s*^(\h*\S.*)){10} to delete the first 10 lines blanks included but it doesn't work well.
(\s*^(\h*\S.*)){10}
In Notepad++, you will need to match the whole document text but only capure lines from 11 to the end.
Find: \A.*(?:\R.*){9}\R?([\s\S]*) Replace: $1
\A.*(?:\R.*){9}\R?([\s\S]*)
$1
To remove the last 10 lines:
Find: ^.*(?:\R.*){9}\z Replace: empty
^.*(?:\R.*){9}\z
Details:
\A
.*
(?:\R.*){9}
\R
\R?
([\s\S]*)
The second regex:
^
\z
$1 is the backreference to the text stored in Group 1.
The result of hitting a Replace All button on a 20+ line document to remove the first 10 lines:
And the last 10 lines:
Just a simple Replace All using this
(?m)(?:\A(?>^.*\R?){10}|(?>^.*\R?){10}\z)
Expanded
(?m) (?: \A (?> ^ .* \R? ){10} | (?> ^ .* \R? ){10} \z )
If it doesn't support the \R syntax, substitute
(?>\r\n|\n|\r|\f|\x0b|\x85) - Ascii (?>\r\n|\n|\r|\f|\x0b|\x85|\x{2028}|\x{2029}) - Unicode
(?>\r\n|\n|\r|\f|\x0b|\x85)
(?>\r\n|\n|\r|\f|\x0b|\x85|\x{2028}|\x{2029})
In Notepad++, you will need to match the whole document text but only capure lines from 11 to the end.
Find:
\A.*(?:\R.*){9}\R?([\s\S]*)
Replace:
$1
To remove the last 10 lines:
Find:
^.*(?:\R.*){9}\z
Replace: empty
Details:
\A
- start of the document.*
- any zero or more chars other than line break symbols (the whole first line)(?:\R.*){9}
- 9 sequences of a line break (\R
) followed with any 0+ chars other than line break chars\R?
- an optional line break (if there are just 10 lines)([\s\S]*)
- Group 1 capturing the rest of the document.The second regex:
^
- start of a line.*
- the line itself up to the line break(?:\R.*){9}
- 9 lines: line break + any 0+ chars other than line break chars\z
- the end of the document.$1
is the backreference to the text stored in Group 1.The result of hitting a Replace All button on a 20+ line document to remove the first 10 lines:
And the last 10 lines: