Community
    • Login

    regex & new line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 8.2k 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.
    • Oli VierO
      Oli Vier
      last edited by

      Hello

      I looked around but cannot find what I was lloking for, so I explain my problem:

      I get the BBCode of an image gallery hosted on ImageBam.com under this form:

      [URL=<link to image number1>][IMG]<link to thumbnail number1>[/IMG][/URL]
      [URL=<link to image number2>][IMG]<link to thumbnail number2>[/IMG][/URL]
      [URL=<link to image number3>][IMG]<link to thumbnail number3>[/IMG][/URL]

      (all on one line, evey link separated by a space)

      I paste this in Notepad++ and use the regex FIND: "[/URL] ", REPLACE: “[/URL] \n”, so I get every link on a separate line (I need this for an easy classification).
      Then I want to put back groups of several links on one line, and I try to use the regex FIND: “\n[URL=”, REPLACE: “[URL=”.
      My problem is here: the replace window says that X occurrences have been replaced, but the display does not change. IF I do it a second time, it says that 0 occurrences have been replaced, so something must have been changed, but it is not possible to see it, and when I paste the result in the forum, I can see that the new lines have not ben removed.
      Thus, I know that this regex works fine, because it works fine when I try to do it in the Wikipedia wikicode editor (with a special gadget that allows to do regex “find and replace” ).

      Can someone please explain me what I could have done wrong, or a better way to do what I want with Notepad++?

      TLDR: how can I remove some “new lines” with regexes?

      Excuse me if my explanations can seem a little bit confuse, but English is not my mother language and it is difficult for me to explain technical things…

      1 Reply Last reply Reply Quote 0
      • Andova BegarinA
        Andova Begarin
        last edited by

        Try it without regular expression checked, and with Extended (\n …) checked.

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

          Hello Oli Vier,

          I quite understood your post, although it’s not your mother language ( nor mine ! ) I tested your regexes and the did work nicely ! So, I suppose it should be a silly problem of options, in the Replace dialog !

          Of course, as I, generally, work with Windows files, I used the \r\n form, instead of the Unix End of Line \n


          So let’s suppose that you have, for instance, the text, below, in an unique long line, in a new tab :

          [URL=<link to image number1>][IMG]<link to thumbnail number1>[/IMG][/URL][URL=<link to image number2>][IMG]<link to thumbnail number2>[/IMG][/URL][URL=<link to image number3>][IMG]<link to thumbnail number3>[/IMG][/URL][URL=<link to image number4>][IMG]<link to thumbnail number4>[/IMG][/URL][URL=<link to image number5>][IMG]<link to thumbnail number5>[/IMG][/URL][URL=<link to image number6>][IMG]<link to thumbnail number6>[/IMG][/URL][URL=<link to image number7>][IMG]<link to thumbnail number7>[/IMG][/URL][URL=<link to image number8>][IMG]<link to thumbnail number8>[/IMG][/URL][URL=<link to image number9>][IMG]<link to thumbnail number9>[/IMG][/URL]
          
          • Open the Replace dialog ( CTRL + H )

          • Set the Extended (\n, \r, \t \0, \x...) search mode ( IMPORTANT )

          • Uncheck the Match whole word only option, if necessary

          • Check the Match case option, if necessary

          • Select the Down direction, if necessary

          • SEARCH [/URL]

          • REPLACE [/URL]\n

          • Click on the Replace All button

          => You obtain , now, the text below :

          [URL=<link to image number1>][IMG]<link to thumbnail number1>[/IMG][/URL]
          [URL=<link to image number2>][IMG]<link to thumbnail number2>[/IMG][/URL]
          [URL=<link to image number3>][IMG]<link to thumbnail number3>[/IMG][/URL]
          [URL=<link to image number4>][IMG]<link to thumbnail number4>[/IMG][/URL]
          [URL=<link to image number5>][IMG]<link to thumbnail number5>[/IMG][/URL]
          [URL=<link to image number6>][IMG]<link to thumbnail number6>[/IMG][/URL]
          [URL=<link to image number7>][IMG]<link to thumbnail number7>[/IMG][/URL]
          [URL=<link to image number8>][IMG]<link to thumbnail number8>[/IMG][/URL]
          [URL=<link to image number9>][IMG]<link to thumbnail number9>[/IMG][/URL]
          
          • Place the cursor, for instance, at the beginning of the line, relative to number3

          • Hold down the Shift key and press, five times, on the Down arrow

          => The lines, relative to number3, number4, number5, number6 and number7, are selected

          => The cursor should be located at the beginning of the non-selected line, relative to number8

          • Now, open, again, the Replace dialog ( CTRL + H )

          • Select the same options, as in the previous S/R

          • Check the In selection option ( IMPORTANT )

          • SEARCH \n[URL=

          • REPLACE [URL=

          • Click on the Replace All button

          => You should get, this time, the text below :

          [URL=<link to image number1>][IMG]<link to thumbnail number1>[/IMG][/URL]
          [URL=<link to image number2>][IMG]<link to thumbnail number2>[/IMG][/URL]
          [URL=<link to image number3>][IMG]<link to thumbnail number3>[/IMG][/URL][URL=<link to image number4>][IMG]<link to thumbnail number4>[/IMG][/URL][URL=<link to image number5>][IMG]<link to thumbnail number5>[/IMG][/URL][URL=<link to image number6>][IMG]<link to thumbnail number6>[/IMG][/URL][URL=<link to image number7>][IMG]<link to thumbnail number7>[/IMG][/URL]
          [URL=<link to image number8>][IMG]<link to thumbnail number8>[/IMG][/URL]
          [URL=<link to image number9>][IMG]<link to thumbnail number9>[/IMG][/URL]
          

          And it’s easy to verify that :

          • The previous non-selected lines, relative to number1, number2, number8 and number9, did not change

          • The selected lines, relative to number3, number4, number5, number6 and number7, have been joined, together, in an unique line

          Et voilà !

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 0
          • Oli VierO
            Oli Vier
            last edited by

            @Andova-Begarin said:

            Try it without regular expression checked, and with Extended (\n …) checked.

            @guy038 said:

            Hello Oli Vier,

            I quite understood your post, although it’s not your mother language ( nor mine ! ) I tested your regexes and the did work nicely ! So, I suppose it should be a silly problem of options, in the Replace dialog !

            guy038

            Спасибо Andova & merci Guy ;)
            It actually works better if “Extended (\n, \r, \t \0, \x…)” is checked.
            I didn’t try this option because I do not use Notepad++ very often and I didn’t knew the use of this “Extended” option.
            I am not really a programmer and I learnt regexes to have a better use of AutoWikiBrowser, an automated wiki editor, so I have only a basic knowledge of it.

            Regards

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