Community
    • Login

    Select bookmarked lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    26 Posts 5 Posters 21.1k 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.
    • guy038G
      guy038
      last edited by

      abuali huma,

      Seemingly, you consider in the original first line, two parts :

      • The first part , which, after replacement, will be moved to the end of this first line

      • The second part, which, after replacement, will follow the contents of the deleted second line

      I, just, supposed that the limit, between these two parts, was the one between ideographic and NON-ideographic characters

      However, any kind of limit may be considered. For instance, if you prefer, we may suppose that group 1 is all the characters of the first line, till a first semicolon or… anything else ! Just tell me which criterion to choose :-))

      Cheers,

      guy038

      abuali humaA 1 Reply Last reply Reply Quote 0
      • abuali humaA
        abuali huma @guy038
        last edited by abuali huma

        @guy038 said:

        abuali huma,

        Seemingly, you consider in the original first line, two parts :

        • The first part , which, after replacement, will be moved to the end of this first line

        • The second part, which, after replacement, will follow the contents of the deleted second line

        I, just, supposed that the limit, between these two parts, was the one between ideographic and NON-ideographic characters

        However, any kind of limit may be considered. For instance, if you prefer, we may suppose that group 1 is all the characters of the first line, till a first semicolon or… anything else ! Just tell me which criterion to choose :-))

        Cheers,

        guy038

        Well let’s see,
        group one should be all characters until the first semicolon
        group two from the semicolon till line ends
        group three should be all characters in the line

        and there’s some lines “minoraty” that contains 5 or 7 groups, but I think I could just duplicate the process.

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

          Hi, abuali huma,

          OK.! So, the general S/R becomes :

          SEARCH (?-si)^(.+?)(;.*)\R(.+)

          REPLACE \3\2\1

          NOTES :

          • The group 2, ( (;.*) ), begins, as expected, with a semicolon, followed by any range, even empty, of standard character(s) ( Remember that the quantifier * is the short form for {0,} ! )

          • The group 1, ( (.+?) ), after the location beginning of line, looks for the shortest, NON-empty, range of standard character, till a semicolon.

          • Note that the form .+?, equivalent to .{1,}? is a lazy quantifier, which forces the regex engine to find the MINIMUM of standard characters till a semicolon => So, in your previous first example, group 1 is equal to the string こんにちは

          • On the contrary, if we have used the greedy quantifier, .+, equivalent to .{1,}, it would have forced the regex engine to find the MAXIMUM of standard characters, till a semicolon. So, in your previous first example, group 1 would have been equal to the string こんにちは;Ax#&, before the second semicolon !

          • The group 3, ( (.+) ), after the EOL character(s) of the first line, represents any NON-empty range of standard characters, of the second line

          • Remember that, as each group contains standard characters, they may, also, begins and/or ends with some space or tabulation character(s), except for group 2, which must begin with a semicolon


          BTW, to know the meaning of the different quantifiers, just see my post to Casey, below :

          https://notepad-plus-plus.org/community/topic/12905/how-to-remove-duplicate-row-in-find-result/4NON-empty

          Best Regards,

          guy038

          hu maH 1 Reply Last reply Reply Quote 1
          • hu maH
            hu ma @guy038
            last edited by

            @guy038 said:

            Hi, abuali huma,

            OK.! So, the general S/R becomes :

            SEARCH (?-si)^(.+?)(;.*)\R(.+)

            REPLACE \3\2\1

            NOTES :

            • The group 2, ( (;.*) ), begins, as expected, with a semicolon, followed by any range, even empty, of standard character(s) ( Remember that the quantifier * is the short form for {0,} ! )

            • The group 1, ( (.+?) ), after the location beginning of line, looks for the shortest, NON-empty, range of standard character, till a semicolon.

            • Note that the form .+?, equivalent to .{1,}? is a lazy quantifier, which forces the regex engine to find the MINIMUM of standard characters till a semicolon => So, in your previous first example, group 1 is equal to the string こんにちは

            • On the contrary, if we have used the greedy quantifier, .+, equivalent to .{1,}, it would have forced the regex engine to find the MAXIMUM of standard characters, till a semicolon. So, in your previous first example, group 1 would have been equal to the string こんにちは;Ax#&, before the second semicolon !

            • The group 3, ( (.+) ), after the EOL character(s) of the first line, represents any NON-empty range of standard characters, of the second line

            • Remember that, as each group contains standard characters, they may, also, begins and/or ends with some space or tabulation character(s), except for group 2, which must begin with a semicolon


            BTW, to know the meaning of the different quantifiers, just see my post to Casey, below :

            https://notepad-plus-plus.org/community/topic/12905/how-to-remove-duplicate-row-in-find-result/4NON-empty

            Best Regards,

            guy038

            Thanks, that is perfect one, it saved me alot of time

            1 Reply Last reply Reply Quote 0
            • abuali humaA
              abuali huma @guy038
              last edited by

              Back again,
              this time I want to swap two sentences or three separated by a symbol.

              example1
              Original

               this is text number two|This is text number one
              

              Result

               This is text number one|this is text number two
              

              Example2

               this is text number three|this is text number two|This is text number one
              

              Result

               This is text number one|this is text number two|this is text number three
              
              1 Reply Last reply Reply Quote 0
              • guy038G
                guy038
                last edited by

                Hi, abuali huma,

                Not very difficult to achieve !


                EXAMPLE 1 :

                SEARCH ^(.+)\|(.+)

                REPLACE \2|\1

                Notes :

                • This first regex separates the two parts of text, before and after the symbol | , which must be escaped ( \| ) as this symbol, in search regexes, stands for the normal alternation symbol !

                • The part, before the symbol, is stored as group 1 and the part, located after, is stored as group 2

                • In replacement, we just reverse the order of these two groups


                EXAMPLE 2

                SEARCH ^(.+?)\|(.+)\|(.+)

                REPLACE \3|\2|\1

                Notes :

                • This second regex separates the three parts of text, created by the symbol |, which are stored as group 1, group 2 and group 3

                • The first part ^(.+?)\|, tries to match, from beginning of line ( ^) , the shortest non-null range of characters, till the FIRST separation symbol ( \| ), because of the lazy quantifier ( +?)

                • Note that if we would have written this first part ^(.+)\|, it would have matched the string this is text number three|this is text number two. Indeed, due to the greedy quantifier ( + ), it would have matched the tallest non-null range of characters, till the SECOND separation symbol !

                • Then for the two remaining parts, of the regex, (.+)\|(.+) just refer to the previous regex for explanations

                • In replacement, we just perform a permutation of these three groups

                Cheers,

                guy038

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