Community
    • Login

    Absolute text editor newbie with a question

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 456 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kevin KorotevK
      Kevin Korotev
      last edited by

      I know nothing about how these programs work, yet I believe there is an answer here if someone could walk me through it or point me to a tutorial designed specifically for newbies/dummies/old people (grin)

      I have a large text file with a lot of sentences/lines/snippets that need to be deleted…leaving me with…voila; the stuff I don’t (bulk) delete .
      These deletions (find and replace with NOTHING) could be described as:
      Find: (Sentences/snippets/paragraphs, etc) that contain: (the word)“unknown” or “family member with” or any number of like FINDS.

      Again, it’s not a case of finding and replacing a string of specific and repeating words: “Written by Jack while on vacation in Bermuda”…but the entire section from previous period to ending period that contains “Jack” or “vacation” or “Bermuda”

      I sure hope that makes sense.
      Help?
      Kevin

      CoisesC 1 Reply Last reply Reply Quote 0
      • CoisesC
        Coises @Kevin Korotev
        last edited by Coises

        @Kevin-Korotev said in Absolute text editor newbie with a question:

        the entire section from previous period to ending period that contains “Jack”

        For this sort of thing you can use what are called “regular expressions.” I wish I could say, “It’s easy!”; well, it can be, but regular expressions are a deep topic, so unless you just happen to get lucky and get exactly what you need from the first thing or two we suggest, prepare for a bit of a learning curve.

        Since you say you are new, I want to start with a warning: Make safety copies of your data before you start editing files! Sometimes you think everything is OK, you save your work… and then realize something you didn’t notice went horribly wrong.

        So, for the example of finding sentences containing “Jack”:

        From the Search menu, choose Replace….

        Near the bottom, in the Search Mode box, select Regular expression. For now, leave the . matches newline box without a check mark.

        Above that, set Match case not checked for now and put a check mark beside Wrap around.

        Now, at the top, in the box labeled Find what, enter this:

        (\A|(?<=\.))[^.]*Jack[^.]*\.

        Try clicking the Find Next button repeatedly and see if that selects, in turn, the things you want to replace.

        Explaining how that works takes a bit of doing.

        The first part, (\A|(?<=\.)), is the most complex. The vertical bar (|) means, “try the part on the left, and if that doesn’t work, try the part on the right.” The part on the left, \A, means “match the very beginning of the document”; the part on the right, (?<=\.) ,means “match here if the preceding character is a period.” The backslash (\) is an escape character that’s needed because normally a period is a special character that means “match any one character”; the backslash causes it to stand for itself and not have a special meaning. The rest of the expression is a kind of formula that means “match here if this (whatever comes after the equals sign and before the closing parenthesis) matches just before here.”

        The next part, [^.], means “match any one character that is not a period.” Once again, the brackets with the circumflex as the first character inside are a kind of formula that means, “match any one character that is not one of the following characters.” (In this context the period isn’t special and doesn’t require an escape character.) The asterisk following that means “repeat the last thing from zero to as many times as necessary.”

        Now, you can follow the rest. Match “Jack,” then match as many characters, other than periods, as necessary, then match a period.

        You might notice some problems. For example, this doesn’t take into account that sentences might end with an exclamation point or a question mark. And it would match “Jackson” just as happily as “Jack,” which might not be what you want.

        If you find that it’s pretty accurate, you can start at the beginning, make sure the Replace with box is empty, and click Replace. First it will find the first match. Then it will replace that match and find the next match. And so on. If you find a match that you don’t want to replace after all, just click Find Next on that one. If you’re feeling really lucky, you can click Replace All.

        Look here for the reference on regular expressions in Notepad++.

        Kevin KorotevK 1 Reply Last reply Reply Quote 3
        • Kevin KorotevK
          Kevin Korotev @Coises
          last edited by

          @Coises
          I can’t Thank-You enough for that “hold my hand” response. It kind of worked the first time. I made an alteration based on your descriptions and it worked perfectly the second time.
          Now I fine tune!
          Wow, I opened a can of worms with this project!
          Thanks so much,
          Kevin Korotev

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors