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.
    • abuali humaA
      abuali huma @Scott Sumner
      last edited by

      @Scott-Sumner said:

      @abuali-huma

      This short script could do it:

      npp_bookmark_marker_id_number = 24
      npp_bookmark_marker_mask = 1 << npp_bookmark_marker_id_number
      line_nbr = editor.markerNext(0, npp_bookmark_marker_mask)
      while line_nbr != -1:
          editor.setSelectionStart(editor.positionFromLine(line_nbr))
          editor.setSelectionEnd(editor.getLineEndPosition(line_nbr))
          editor.replaceSel(editor.getSelText().decode('utf8')[::-1].encode('utf8'))
          line_nbr = editor.markerNext(line_nbr + 1, npp_bookmark_marker_mask)
      

      Thanks, that saved my day!

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

        What if i want to do this?

        Original
        Line#1 Aaaaaa;Ax#&;Dx#&
        Line#2 Bbbbb

        Result
        Line#1 Bbbbb;Ax#&;Dx#&Aaaaaa

        And again with unicode character texts also

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

          Sorry if the previous isn’t clear example
          better example would be

          Original
          Line#1 FGHI;Ax#&;Dx#&
          Line#2 BCDE

          Result
          Line#1 BCDE;Ax#&;Dx#&FGHI

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

            Hi, hu ma,

            Ah! I see ! You’re using CJK ideographic characters !

            The different Unicode CJK scripts are :

            - CJK Radicals Supplement - Phonetics and Symbols  (  2E80 -  2EFF )
            - CJK Kangxi Radicals                              (  2F00 -  2FDF )
            - CJK Ideographic Description Characters           (  2FF0 -  2FFF )
            - CJK Symbols and Punctuation                      (  3000 -  303F )
            - CJK Strokes                                      (  31C0 -  31EF )
            - CJK Enclosed Letters and Months                  (  3200 -  32FF )
            - CJK Compatibility                                (  3300 -  33FF )
            - CJK Unified Ideographs Extension A               (  3400 -  4DB5 )
            - CJK Unified Ideographs                           (  4E00 -  9FD5 )
            - CJK Compatibility Ideographs                     (  F900 -  FAFF )
            - CJK Compatibility Forms                          (  FE30 -  FE4F )
            - CJK Half-width Punctuation                       (  FF61 -  FF64 )
            - CJK Unified Ideographs Extension B               ( 20000 - 2A6D6 )
            - CJK Unified Ideographs Extension C               ( 2A700 - 2B734 )
            - CJK Unified Ideographs Extension D               ( 2B740 - 2B91D )
            - CJK Compatibility Ideographs Supplement          ( 2F800 - 2FA1F )
            

            As I have Asiatic languages, installed in my Win XP configuration, I chose the SimSun font to give you an example of my regex search/replacement, which does work, perfectly well !

            In this example, the regex looks, successively, for the three following characters, enclosed by two angle brackets <> :

            • The second character, of your range [\x{3000}-\x{9faf}], known in my SimSun font, ( 、 ), of Unicode code-point \x{3001}

            • A character, in the middle of your range [\x{3000}-\x{9faf}] , ( 栀 ), of Unicode code-point \x{6800}

            • The last character, of your range [\x{3000}-\x{9faf}], known in my SimSun font, ( 龥 ), of Unicode code-point \x{9fa5}

            Moreover, I added some random values :

            • The three characters 一倀怀, of Unicode code-points \x{4e00}\x{5000}\x{6000}, before the searched string

            • The three characters 瀀耀退, of Unicode code-points \x{7000}\x{8000}\x{9000}, after the searched string

            And, in replacement, I inserted the string Inserted灭Text, containing the ideographic character 灭, of Unicode code-point \x{706d}


            So, starting with the original text, with an UTF-8 encoding :

            一倀怀<、>瀀耀退
            一倀怀<栀>瀀耀退
            一倀怀<龥>瀀耀退
            

            The first S/R :

            SEARCH ^.*<[\x{3000}-\x{9faf}]>

            REPLACE Inserted灭Text$0

            gives the resulting text :

            Inserted灭Text一倀怀<、>瀀耀退
            Inserted灭Text一倀怀<栀>瀀耀退
            Inserted灭Text一倀怀<龥>瀀耀退
            

            And the second S/R :

            SEARCH <\x{3000}-\x{9faf}]>.*

            REPLACE $0Inserted灭Text

            gives the final text :

            一倀怀<、>瀀耀退Inserted灭Text
            一倀怀<栀>瀀耀退Inserted灭Text
            一倀怀<龥>瀀耀退Inserted灭Text
            

            Cheers,

            guy038

            P.S. :

            I just saw your recent post. Let’s me a couple of minutes to think about it. I’m back , soon !

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

              @guy038 said:

              Hi, hu ma,

              Ah! I see ! You’re using CJK ideographic characters !

              The different Unicode CJK scripts are :

              - CJK Radicals Supplement - Phonetics and Symbols  (  2E80 -  2EFF )
              - CJK Kangxi Radicals                              (  2F00 -  2FDF )
              - CJK Ideographic Description Characters           (  2FF0 -  2FFF )
              - CJK Symbols and Punctuation                      (  3000 -  303F )
              - CJK Strokes                                      (  31C0 -  31EF )
              - CJK Enclosed Letters and Months                  (  3200 -  32FF )
              - CJK Compatibility                                (  3300 -  33FF )
              - CJK Unified Ideographs Extension A               (  3400 -  4DB5 )
              - CJK Unified Ideographs                           (  4E00 -  9FD5 )
              - CJK Compatibility Ideographs                     (  F900 -  FAFF )
              - CJK Compatibility Forms                          (  FE30 -  FE4F )
              - CJK Half-width Punctuation                       (  FF61 -  FF64 )
              - CJK Unified Ideographs Extension B               ( 20000 - 2A6D6 )
              - CJK Unified Ideographs Extension C               ( 2A700 - 2B734 )
              - CJK Unified Ideographs Extension D               ( 2B740 - 2B91D )
              - CJK Compatibility Ideographs Supplement          ( 2F800 - 2FA1F )
              

              As I have Asiatic languages, installed in my Win XP configuration, I chose the SimSun font to give you an example of my regex search/replacement, which does work, perfectly well !

              In this example, the regex looks, successively, for the three following characters, enclosed by two angle brackets <> :

              • The second character, of your range [\x{3000}-\x{9faf}], known in my SimSun font, ( 、 ), of Unicode code-point \x{3001}

              • A character, in the middle of your range [\x{3000}-\x{9faf}] , ( 栀 ), of Unicode code-point \x{6800}

              • The last character, of your range [\x{3000}-\x{9faf}], known in my SimSun font, ( 龥 ), of Unicode code-point \x{9fa5}

              Moreover, I added some random values :

              • The three characters 一倀怀, of Unicode code-points \x{4e00}\x{5000}\x{6000}, before the searched string

              • The three characters 瀀耀退, of Unicode code-points \x{7000}\x{8000}\x{9000}, after the searched string

              And, in replacement, I inserted the string Inserted灭Text, containing the ideographic character 灭, of Unicode code-point \x{706d}


              So, starting with the original text :

              一倀怀<、>瀀耀退
              一倀怀<栀>瀀耀退
              一倀怀<龥>瀀耀退
              

              The first S/R :

              SEARCH ^.*<[\x{3000}-\x{9faf}]>

              REPLACE Inserted灭Text$0

              gives the resulting text :

              Inserted灭Text一倀怀<、>瀀耀退
              Inserted灭Text一倀怀<栀>瀀耀退
              Inserted灭Text一倀怀<龥>瀀耀退
              

              And the second S/R :

              SEARCH [\x{3000}-\x{9faf}]>.*

              REPLACE $0Inserted灭Text

              gives the final text :

              一倀怀<、>瀀耀退Inserted灭Text
              一倀怀<栀>瀀耀退Inserted灭Text
              一倀怀<龥>瀀耀退Inserted灭Text
              

              Cheers,

              guy038

              P.S. :

              I just saw your recent post. Let’s me a couple of minutes to think about it. I’m back , soon !

              I see bunch of options here I could use, thanks for the information

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

                Hello, abuali huma,

                You didn’t say if the regex must keep the Line 2 unchanged or if you want to wipe out this line !

                Anyway, here are the appropriate regexes for each case :

                • 1) If line 2 is unchanged :

                From the original text :

                FGHI;Ax#&;Dx#&
                BCDE
                

                the S/R, below :

                SEARCH (?-si)^(FGHI)(.*)(?=\R(BCDE))

                REPLACE \3\2\1

                would give the result :

                BCDE;Ax#&;Dx#&FGHI
                BCDE
                

                NOTES :

                • The first part (?-si) forces the dot ( . ) to match standard characters, only, and the regex engine to work, in a NON-insensitive way

                • The \R form represents any kind of EOL characters (\r\n ), (\n ) or (\r )

                • The (?=\R(BCDE)) syntax is called a positive look-ahead, that is to say a condition which must be verified to valid the overall regex, but which is never part of the final match. So the condition is “Does it exist, at the end of line 1, some EOL character(s), followed by the string BCDE ?”. The string BCDE is stored in group 3


                • 2) If line 2 must be deleted, too :

                From the original text :

                FGHI;Ax#&;Dx#&
                BCDE
                

                The second S/R :

                SEARCH (?-si)^(FGHI)(.*)\R(BCDE)

                REPLACE \3\2\1

                would give the final text :

                BCDE;Ax#&;Dx#&FGHI
                

                Best Regards,

                guy038

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

                  @guy038 said:

                  Hello, abuali huma,

                  You didn’t say if the regex must keep the Line 2 unchanged or if you want to wipe out this line !

                  Anyway, here are the appropriate regexes for each case :

                  • 1) If line 2 is unchanged :

                  From the original text :

                  FGHI;Ax#&;Dx#&
                  BCDE
                  

                  the S/R, below :

                  SEARCH (?-si)^(FGHI)(.*)(?=\R(BCDE))

                  REPLACE \3\2\1

                  would give the result :

                  BCDE;Ax#&;Dx#&FGHI
                  BCDE
                  

                  NOTES :

                  • The first part (?-si) forces the dot ( . ) to match standard characters, only, and the regex engine to work, in a NON-insensitive way

                  • The \R form represents any kind of EOL characters (\r\n ), (\n ) or (\r )

                  • The (?=\R(BCDE)) syntax is called a positive look-ahead, that is to say a condition which must be verified to valid the overall regex, but which is never part of the final match. So the condition is “Does it exist, at the end of line 1, some EOL character(s), followed by the string BCDE ?”. The string BCDE is stored in group 3


                  • 2) If line 2 must be deleted, too :

                  From the original text :

                  FGHI;Ax#&;Dx#&
                  BCDE
                  

                  The second S/R :

                  SEARCH (?-si)^(FGHI)(.*)\R(BCDE)

                  REPLACE \3\2\1

                  would give the final text :

                  BCDE;Ax#&;Dx#&FGHI
                  

                  Best Regards,

                  guy038

                  What if it is different text?
                  Example one
                  Line#1 こんにちは;Ax#&;Dx#&
                  Line#2 行く
                  Result
                  Line#1 行く ;Ax#&;Dx#&こんにちは

                  Example two
                  Line#18 細かい ;Ax#&;Dx#&
                  Line#19 自分を愛する
                  Result
                  Line#18 自分を愛する ;Ax#&;Dx#& 細かい

                  and so on, and yes 2nd line is supposed to be deleted

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

                    Hi, abuali huma,

                    Sorry, I was absent for a while, because of an virus analysis on my laptop ! But, please be quiet : absolutely NO connection with our NodeBB site nor our discussion, too :-))

                    For a general regex, no problem at all ! I just interpreted that :

                    • Group 1, beginning the first line, is supposed to contain ideographic characters, ONLY

                    • Group 2 represents any range, after the last ideographic character, in the first line, till the end of the line

                    • Group 3, standing for the second line, is supposed, also, to contain ideographic characters, ONLY

                    Remark :

                    Some additional space characters, NOT present in the original text, seem included in the replacement text, of your two examples :

                    • Before the first semicolon, in your first example

                    • After the ampersand character, in your second example

                    From my hypotheses, any space character would be stored in group 2, of course !. In addition, you may separate, in replacement, the three groups with a space character, as well !


                    So, a general S/R would be :

                    SEARCH (?-si)^([\x{3000}-\x{9faf}]+)(.*)\R([\x{3000}-\x{9faf}]+)

                    REPLACE \3\2\1

                    Notes :

                    • The part [\x{3000}-\x{9faf}]+ tries to match the largest, non empty, range of ideographic characters, from beginning of a line ( ^ ), stored in group 1 OR after an EOL character (\R ), stored in group 3

                    • During replacement, these three groups, on two consecutive lines, are, just, re-written, in a single line, into a different order !

                    • As said above, the replacement regex may be changed into \3 \2 \1

                    Cheers,

                    guy038

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

                      @guy038 said:

                      Hi, abuali huma,

                      Sorry, I was absent for a while, because of an virus analysis on my laptop ! But, please be quiet : absolutely NO connection with our NodeBB site nor our discussion, too :-))

                      For a general regex, no problem at all ! I just interpreted that :

                      • Group 1, beginning the first line, is supposed to contain ideographic characters, ONLY

                      • Group 2 represents any range, after the last ideographic character, in the first line, till the end of the line

                      • Group 3, standing for the second line, is supposed, also, to contain ideographic characters, ONLY

                      Remark :

                      Some additional space characters, NOT present in the original text, seem included in the replacement text, of your two examples :

                      • Before the first semicolon, in your first example

                      • After the ampersand character, in your second example

                      From my hypotheses, any space character would be stored in group 2, of course !. In addition, you may separate, in replacement, the three groups with a space character, as well !


                      So, a general S/R would be :

                      SEARCH (?-si)^([\x{3000}-\x{9faf}]+)(.*)\R([\x{3000}-\x{9faf}]+)

                      REPLACE \3\2\1

                      Notes :

                      • The part [\x{3000}-\x{9faf}]+ tries to match the largest, non empty, range of ideographic characters, from beginning of a line ( ^ ), stored in group 1 OR after an EOL character (\R ), stored in group 3

                      • During replacement, these three groups, on two consecutive lines, are, just, re-written, in a single line, into a different order !

                      • As said above, the replacement regex may be changed into \3 \2 \1

                      Cheers,

                      guy038

                      Thanks mate, I will give it a try once I get back on my pc after a while…

                      But as I understand from you, that is in group 1&3, if the line had mixed character set, the regex will not apply to that line ?

                      1 Reply Last reply Reply Quote 0
                      • 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