Community
    • Login

    Need help on replacing text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 2 Posters 3.3k 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.
    • Claude CadieuxC
      Claude Cadieux
      last edited by

      @Alan-Kilborn said in Need help on replacing text:

      ABT(?= \d{4}-\d{4})

      Worked perfectly. Thank you very much.

      This topic may be closed.

      Claude

      1 Reply Last reply Reply Quote 2
      • Claude CadieuxC
        Claude Cadieux @Alan Kilborn
        last edited by

        @Alan-Kilborn said in Need help on replacing text:

        ABT(?= \d{4}-\d{4})

        Sorry to ask another question about this.
        The change worked from ABT to BET but I must make another change if you can spare a moment.
        I need to change this line:
        2 DATE BET 1676-1678

        to this:
        2 DATE BET 1676 AND 1678

        Replacing the “-” between the 2 dates by " AND "

        Thanks again.
        Claude

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Claude Cadieux
          last edited by Alan Kilborn

          @Claude-Cadieux

          So given our first exchange, might you see which part of that pattern I provided matches four-digit years? Go ahead, take a guess! We’ll be kind.

          While we do like providing help, we really enjoy it when people take the help provided and apply it to new problems. Makes us happy.

          Claude CadieuxC 1 Reply Last reply Reply Quote 2
          • Claude CadieuxC
            Claude Cadieux @Alan Kilborn
            last edited by

            @Alan-Kilborn
            I did look at your example and tried some variant but they did not work. Then went to look at Regex example online but man, at 65 I must say that I am a bit overwhelmed.
            I tried this:
            -(?= \d{4}-\d{4})

            I tried this:
            -(?= \d{4}-\d{4})

            Can’t get a match and also, I need to insert a blank before and after “AND”.
            \bAND\b ??

            Thanks

            Claude CadieuxC 1 Reply Last reply Reply Quote 0
            • Claude CadieuxC
              Claude Cadieux @Claude Cadieux
              last edited by

              @Claude-Cadieux said in Need help on replacing text:

              -(?= \d{4}-\d{4})

              Sorry on the second try I did this:
              -(?= \d{4}-\d{4})

              Claude CadieuxC Alan KilbornA 2 Replies Last reply Reply Quote 0
              • Claude CadieuxC
                Claude Cadieux @Claude Cadieux
                last edited by

                @Claude-Cadieux
                Backslash does not show here \-(?= \d{4}-\d{4})

                1 Reply Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @Claude Cadieux
                  last edited by

                  @Claude-Cadieux

                  So to match a 4-digit year you can use \d{4}. That means “a digit character repeated 4 times”.

                  A blank is not \b. A blank space is just a blank space in your expression.

                  \b is actually a word-boundary.

                  It is best to show expressions surrounded by backticks; they will appear like mine do, in red.

                  Alan KilbornA 1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @Alan Kilborn
                    last edited by Alan Kilborn

                    @Claude-Cadieux

                    went to look at Regex example online but man, at 65 I must say that I am a bit overwhelmed

                    I would not believe you if you said anything different. :-)

                    So by now you should be matching 1968-1974 as \d{4}-\d{4} ??

                    Admittedly, my earlier stuff with (?= before it might have been misleading. Forget about that now (advanced usage).

                    Claude CadieuxC 1 Reply Last reply Reply Quote 0
                    • Claude CadieuxC
                      Claude Cadieux @Alan Kilborn
                      last edited by

                      @Alan-Kilborn
                      Yes this did work: \d{4}-\d{4}
                      But it must be on a BET line:
                      2 DATE BET 1625-1629
                      So this also works to find the right line
                      BET(?= \d{4}-\d{4})

                      But I do not know how to specify the “-” being the target to change by " AND "

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Claude Cadieux
                        last edited by Alan Kilborn

                        @Claude-Cadieux

                        So there may be something to learn here. With BET(?= \d{4}-\d{4}) (you didn’t apply my “backtick” advice when you stated it), you can’t possibly influence the - because the (?=...) part of that doesn’t match any text, it just means that the specified text must be there. If you don’t match the text you want, you can’t replace it. (Remember, originally, all we wanted to replace was some fixed text before the (variable) year range).

                        You might have good luck searching for BET (\d{4})-(\d{4}) and replacing with BET \1 AND \2.
                        You put grouping parentheses around variable text that you want to substitute in at replace time, as I’ve done here. Then, to refer to the first capturing group, at replace time you reference it with \1. Similar for the second grouping.

                        But really, this isn’t a forum about regular expressions, so time to buck up and learn a bit more than just your immediate need covers. There’s some good pointers here: https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regex-documentation

                        Claude CadieuxC 1 Reply Last reply Reply Quote 2
                        • Claude CadieuxC
                          Claude Cadieux @Alan Kilborn
                          last edited by

                          @Alan-Kilborn said in Need help on replacing text:

                          BET \1 AND \2

                          Thank you so much for your time and patience and the link.
                          There’s always something new to learn.
                          Claude :-)

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