how do i delete the whole line based on a find argument
-
i want to delete lines from a document that contain certain text … eg “page no”
-
In regular expressions (docs linked below),
^
matches start of line,.*?
matches 0 or more characters,page no
will match the literal text,.*?
matches 0 or more characters, and(\R|\Z)
matches either the newline characters at the end of a line\R
, or the end of the file\Z
. Put that all together, and replace with nothing, and you will match from the beginning of the line, through the newline at the end of the line, as long aspage no
exists on that line.To make this work, you need Search mode = regular expression and you need to make sure that
. matches newline
is turned off (not checked).- FIND =
^.*?page no.*$(\R|\Z)
- REPLACE = leave empty
- Search Mode = regular expression
☐ . matches newline
is not checked
----
Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the
</>
toolbar button or manual Markdown syntax. To makeregex in red
(and so they keep their special characters like *), use backticks, like`^.*?blah.*?\z`
. Screenshots can be pasted from the clipboard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.----
*Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will happily give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
- FIND =
-
There is also a solution without using regular expression searches.
- Open the
Find
dialog box and navigate to registerMark
. - Enter your search tag in
Find what
. - Tick option
Bookmark line
. You may also tick optionsPurge for each search
andWrap around
. Furthermore tick optionNormal
inSearch mode
group box. - Click on button
Mark All
. - Navigate to
(menu) Search -> Bookmark
and click on submenu entryRemove Bookmarked Lines
.
- Open the