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”



  • @Ben-Robertshawe ,

    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 as page 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 make regex 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 using Ctrl+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.



  • @Ben-Robertshawe

    There is also a solution without using regular expression searches.

    1. Open the Find dialog box and navigate to register Mark.
    2. Enter your search tag in Find what.
    3. Tick option Bookmark line. You may also tick options Purge for each search and Wrap around. Furthermore tick option Normal in Search mode group box.
    4. Click on button Mark All.
    5. Navigate to (menu) Search -> Bookmark and click on submenu entry Remove Bookmarked Lines.

Log in to reply