Community
    • Login

    'Find and Replace' question

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 4 Posters 5.0k Views 3 Watching
    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.
    • Oleg NemchenkoO Offline
      Oleg Nemchenko
      last edited by

      Thank you so much Claudia!
      That code actually works and finds all the instances it supposed to.
      But I have problems with replacement now…
      It should be same numbers with same sequence, just without quotes - like, PR1=‘0066’ or PR1=‘3601’ or PR1=‘3722’… after replacement should be -> PR1=0066 or PR1=3601 or PR1=3722…
      Is it possible to make find and replace to leave the same numbers after adding or deleting quotes?
      Mb there is other way to add/delete quotes in sequence where PR1= is constant, but numbers are different and just randomly assigned?

      Claudia FrankC 1 Reply Last reply Reply Quote 1
      • Claudia FrankC Offline
        Claudia Frank @Oleg Nemchenko
        last edited by

        @Oleg-Nemchenko

        you just wanna get rid of the single quotes?
        PR1= and number should stay?

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Oleg NemchenkoO Offline
          Oleg Nemchenko
          last edited by

          That`s correct. PR1=and number should stay for each instance of PR1=number1, PR1=number2 …PR1=numberN

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC Offline
            Claudia Frank @Oleg Nemchenko
            last edited by

            @Oleg-Nemchenko

            not the most elegant but in find what use

            (?<=PR1=)(')(\d+)(')
            

            and in replace with use backslash 2

            \2
            

            Cheers
            Claudia

            Oleg NemchenkoO 1 Reply Last reply Reply Quote 1
            • Oleg NemchenkoO Offline
              Oleg Nemchenko @Claudia Frank
              last edited by

              @Claudia-Frank said:

              @Oleg-Nemchenko

              (?<=PR1=)(')(\d+)(')
              

              and in replace with use backslash 2

              \2
              

              Cheers
              Claudia

              Thank you so so much! Pure magic! :)

              Claudia FrankC 1 Reply Last reply Reply Quote 0
              • Claudia FrankC Offline
                Claudia Frank @Oleg Nemchenko
                last edited by

                @Oleg-Nemchenko

                you’re welcome - but if you really wanna see pure magic checkout
                the regex tips from guy038 and the other regex gurus :-D

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 1
                • Oleg NemchenkoO Offline
                  Oleg Nemchenko
                  last edited by

                  That`s my plan :)

                  1 Reply Last reply Reply Quote 1
                  • guy038G Offline
                    guy038
                    last edited by guy038

                    Hello @oleg-nemchenko, @claudia-frank and All,

                    Or even more simple :

                    SEARCH (?<=PR1=)'(\d+)'

                    REPLACE \1

                    Notes :

                    • If necessary, check the Match case option, if the case pr=1 may happen !

                    • Due to the look-behind feature (?<=PR1=), you cannot use the Replace button, successively and must, exclusively, use the Replace All button !!

                    Cheers,

                    guy038

                    P.S. :

                    For newby people, about regular expressions concept and syntax, begin with that article, in N++ Wiki :

                    http://docs.notepad-plus-plus.org/index.php/Regular_Expressions

                    In addition, you’ll find good documentation, about the Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v5.8 ), used by Notepad++, since its 6.0 version, at the TWO addresses below :

                    http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

                    http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

                    • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

                    • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part


                    You may, also, look for valuable informations, on the sites, below :

                    http://www.regular-expressions.info

                    http://www.rexegg.com

                    http://perldoc.perl.org/perlre.html

                    Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))

                    1 Reply Last reply Reply Quote 2
                    • Oleg NemchenkoO Offline
                      Oleg Nemchenko
                      last edited by

                      Hello @guy038,

                      Thank you so much for taking your time and answering in this theme!
                      Could you also help with reverse replacement: adding quotation marks before and after numbers (it`s always 4 numbers in a row preceding by PR1=) like PR1=0066 or PR1=3601 or PR1=3722 -> PR1=‘0066’ or PR1=‘3601’ or PR1=‘3722’

                      Scott SumnerS 1 Reply Last reply Reply Quote 0
                      • Scott SumnerS Offline
                        Scott Sumner @Oleg Nemchenko
                        last edited by Scott Sumner

                        @Oleg-Nemchenko

                        I would do it like this:

                        Note: Before text: PR1='0123' PR1=7777 PR1='0000' PR1=3456

                        Case 1: PR1=‘1234’ —> PR1=1234 (remove quotes):

                        Find-what zone: (?-i)PR1='(\d{4})'
                        Replace-with zone: PR1=\1
                        After text: PR1=0123 PR1=7777 PR1=0000 PR1=3456

                        Case 2: PR1=1234 —> PR1=‘1234’ (add quotes):

                        Find-what zone: (?-i)PR1=(\d{4})
                        Replace-with zone: PR1='\1'
                        After text: PR1='0123' PR1='7777' PR1='0000' PR1='3456'

                        Case 3: PR1=‘1234’ —> PR1=1234 & at same time PR1=4321 —> PR1=‘4321’ (add and remove quotes at same time):

                        Find-what zone: (?-i)PR1=(')?(\d{4})(')?
                        Replace-with zone: PR1=(?1:')\2(?3:')
                        After text: PR1=0123 PR1='7777' PR1=0000 PR1='3456'

                        For any of these cases, you do not have to use the Replace All button, although you may. Find Next and Replace combinations to selectively replace is fine.

                        Oleg NemchenkoO 1 Reply Last reply Reply Quote 3
                        • Oleg NemchenkoO Offline
                          Oleg Nemchenko @Scott Sumner
                          last edited by Oleg Nemchenko

                          @Scott-Sumner that`s amazing. Thank you very much for your help!

                          1 Reply Last reply Reply Quote 1

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors