Community
    • Login

    Want to delete everything like [xxx] including []

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 4 Posters 9.6k 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.
    • David ChiuD
      David Chiu
      last edited by

      Hi all,
      I have some text which will have some reference in [xx] which I would like to delete.

      Eg.
      Original text: The population is 6000 [1].
      Desired text: The population is 6000.

      And remove [1], there are other similar occurrences like [2] , [3] and so on. And I want to remove all.
      I guess I can use search all instances [xx] and replace them with a null. But not know how it can be done in action.

      Thanks in advance.

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

        Hello, David,

        I’ve got to be out this afternoon. So, here is a quick S/R solution that implies regular expressions. I’ll give you some details, if necessary, in a next post !

        • Preferably, move back to the very beginning of your file ( CTRL + Origin )

        • Open the Replace dialog ( CTRL + H )

        • Type the regex \x20\[\d+\](?=.?$) in the Find what: zone

        • Leave the Replace with: zone EMPTY

        • Select the Regular expression search mode ( IMPORTANT )

        • Click on the Replace All button

        Et voilà !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • David ChiuD
          David Chiu
          last edited by

          Thanks, Guy038,

          I followed the instruction, but it does not work.

          It finds no occurrence.

          My sample text is copied and pasted below:

          In a 2004 revision of headache classification, the term “Complicated migraine” was replaced by “Complications of migraine” [3]. The 2004 and 2013 revisions also reclassified some syndromes unique to children that historically were considered manifestations of migraine.

          Scott SumnerS 1 Reply Last reply Reply Quote 0
          • David ChiuD
            David Chiu
            last edited by

            I just tried and experiment myself and found that if I use the following, it works. But i am not sure if it works for a large file size normally.

            I use [\d+] in the Fine what zone. I am not sure what \20x, (?=.?$) for.

            1 Reply Last reply Reply Quote 0
            • Scott SumnerS
              Scott Sumner @David Chiu
              last edited by

              @David-Chiu

              In asking a question here, you have to be careful to provide enough information to receive good help. @guy038 's solution works for your original data and not for your new example data because he was mislead by contraints on the context that were untrue.

              That being said, modifying his “Find what” regex to \x20[\d+] will likely work for your new data (as well as the old). The translation into English of this regex is (loosely): find a space followed by a left bracket followed by an integer number (of one or more digits) followed by a right bracket. Replacing this with nothing deletes what was matched with the find.

              1 Reply Last reply Reply Quote 0
              • David ChiuD
                David Chiu
                last edited by

                Thanks Scott. Will provide more precise and enough information next time.

                All is well now. Thank you all !

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

                  Hi David,

                  Ah, yes ! I supposed that the reference always ends your text. Moreover, I was mistaken about my previous regex. The correct syntax should have been, as below :

                  \x20\[\d+\](?=\.?$)

                  • First, this regex looked for a space character, of Unicode code-point U+0032 ( = \x20, in hexadecimal ) Of course, I could have shortened it to a simple space character ( " " ), but it’s not easy to show that blank character, in posts !

                  • Then, it searched for an opening square bracket, \[. As it’s a special regex character, it must be escaped with an anti-slash, \, in order to be taken, literally

                  • After, it looked for a NON-empty range of digits \d+, as the + sign is a quantifier, which means from 1 to n times ( whatever n ), the previous element \d

                  • Then it searched for an ending square bracket \], with the same remark as for the [ symbol

                  • Finally, the overall match is true ONLY IF the condition (?=\.?$), called a positive look-ahead, is true. That condition means that, after the ending square bracket, the end of line $ must be reached, eventually preceded by a literal dot character, \.? ( Note that ? is also a quantifier, which means 0 or 1 time, the preceding element \.. Indeed, I thought that the ending dot could be absent from some of your lines !

                  Of course, if we decide not to be so restrictive, the correct search regex is, simply :

                  \[\d+\] , with a SPACE character, before the first antislash symbol

                  Cheers,

                  guy038

                  P.S.,

                  If you’re a newby, 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 new Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v1.48.0 ), used by Notepad++, since its 6.0 version, at the TWO addresses below :

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

                  http://www.boost.org/doc/libs/1_48_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

                  1 Reply Last reply Reply Quote 0
                  • David ChiuD
                    David Chiu
                    last edited by

                    Hi Guy038,

                    Thank you for your detailed explanation and I have visited some of your mentioned website. As I am a newbie, I do need some time.

                    The

                    \ [ \ d + \ ]

                    (Sorry I have to break the above code by space and if not, it does not show properly. I don’t know how to do like yours in coloured background.)

                    This works most closely for me, but then I noted some reference is like this [11,13] and [14-16]. And this expression dose not work for these reference quote.

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

                      I, too, do not know how @guy038 obtains the red text in the light-red background here in this forum Community, but I would like to know how to do it myself!

                      @David-Chiu , you can match your new text with a regular expression of the form:

                      \x20\[\d+([,-]\d+)?\]
                      

                      I suppose the next question will be something about how to do [11,12,13] but here is where the learning part comes in! Read about regular expressions on the reference sites @guy038 mentioned, and practice!

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

                        Hi, David and Alan,

                        See, below, the different ways to get emphasis and blocks of code :

                        *section in italic*                 =>        section in italic
                        **section in bold**             =>         section in bold
                        `section of code`                 =>       section of code

                        *section`of code` in italic*       =>      section of code in italic
                        **section`of code` in bold**    =>      section of code in bold

                        ....This text needs to be
                        ....indented with four spaces
                        ....characters and preceded with
                        ....a blank line, in order to be
                        ....seen as a block of code

                        =>

                        This text needs to be
                        indented with FOUR spaces
                        characters and preceded with
                        a BLANK line,  in order to be
                        seen as a BLOCK of CODE
                        

                        For full documentation, about Markdown syntax, refer to the link below :

                        http://daringfireball.net/projects/markdown/syntax

                        And, for emphasis consult the section :

                        http://daringfireball.net/projects/markdown/syntax#em


                        David, I succeeded to find out the right regex, in order to match the eight the references, below :

                        References [3] and [123] and [11,13] and [14-16]
                        
                        References [10,14-16] and [3-15,20-42] and [3,8,12,17] and [1-3,12-18,20-30,43,57,60-70]
                        

                        So :

                        SEARCH \x20\[(,?\d+(-\d+)?)+\]

                        REPLACE EMPTY

                        Note : I suppose that there is NOT any space character, inside the square brackets area !


                        Alan, thanks for helping David, with your regex \x20\[\d+([,-]\d+)?\]. Indeed, it matches the first four examples of reference, above :-) So, it should be OK for David ! However, it fails to match the last four types of reference. But, certainly, David doesn’t need these complicated references, anyway !

                        Cheers,

                        guy038

                        Alan KilbornA 1 Reply Last reply Reply Quote 3
                        • David ChiuD
                          David Chiu
                          last edited by

                          Hi Guy and Alan,

                          Thank you for your kind help. It is also easier to learn by studying your suggestion along with the web link reference.

                          \[(,?\d+(-\d+)?)+\] is the final one I needed as I noted there is not always a space in front of the reference quote. so I have to omit \x20

                          Thank you very much again.

                          Cheers
                          David

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

                            @guy038

                            Thanks for the information on how to format posts here on this website. One thing I didn’t see in the documentation is how to separate normal text (not in a codeblock) with some extra whitespace. For example, if I want to put extra spaces between “a” and “b” here:

                            a b

                            So when I typed that line above I put a gob of spaces between the a and the b. But the preview pane (and when I submit the post, I imagine) simply shows “a b”…single space between. Is this type of extra whitespacing possible with some extra markup/markdown syntax?

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

                              Hello Alan,

                              To write consecutive spaces, in normal text of posts, on NodeBB N++ forum, I replace the common SPACE character ( \x{0020} ) by the NO-BREAK SPACE character ( \x{00A0} )

                              To write this character, at the current cursor location, TWO solutions :

                              • Select the menu option Edit > Character Panel and double-click on the line, of decimal value 160

                              • Hold down the ALT key and hit, successively, on the four NUMPAD keys 0, 1, 6 and 0, before releasing the ALT key

                              Remark :

                              • As browsers don’t use, generally, monospaced fonts, the physical size of a “space” character family, is smaller than a letter or digit size ! Roughly, you need three consecutive “space” characters to get the same width than a word character !

                              An example :

                              TEST about the NodeBB displaying of the NO-BREAK SPACE character ( \x00A0 )

                              12345678901234567890 = A line with digits, without any SPACE character

                              12 45 78 01 34 67 90 = The same line, where six digits, have been replaced by a single SPACE character => Line shorter than the first one

                              12 45 78 01 34 67 90 = The same line, where six digits, have been replaced by three SPACE characters => Identical to the previous one

                              12   45   78   01   34   67   90 = The same line, where six digits, have been replaced by three NO-BREAK SPACE characters

                              => This time, total spacing seem to be kept !

                              Best Regards,

                              guy038

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

                                Hello Mr. Guy,

                                I think I see what you mean, although at first I didn’t. I was trying to type a literal \ followed by x followed by { … followed by } in the box I type in to make a post on this website. But…that didn’t work correctly in the Preview area.

                                Then it dawned on me that if I type my posting in Notepad++ FIRST (using the Character Panel method), then copy and paste it to the website, it works to make wide         open        spaces!

                                Thank you for your help.
                                AK

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