Community
    • Login

    regexp with hashes help

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regexregex
    16 Posts 3 Posters 3.7k Views 2 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.
    • patrickdrdP Offline
      patrickdrd
      last edited by

      hello,

      I would like some help with a regexp I was trying to write a couple of days ago but I didn’t succeed,

      well,

      I want to select wholes lines (in order to delete them with \1) which contain “#” (without the quotation marks of course) in any positon, but only those that aren’t followed immediately after by “#” or by “@”

      for the time being I ended up with #\s, but what I’m asking would be more effective obviously,

      thanks in advance

      1 Reply Last reply Reply Quote 0
      • patrickdrdP Offline
        patrickdrd
        last edited by

        hmm, it seems there are cases like this too that I would like to exclude:
        google.*###center_col > #resultStats + div[style=“border:1px solid #dedede;margin-bottom:11px;padding:5px 7px 5px 6px”]

        so maybe the hash has to be the only hash in the line

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

          @patrickdrd

          Your request is unclear. I want to say that you want to match all lines with exactly one # character occurring in them, but I don’t think that is correct…

          1 Reply Last reply Reply Quote 0
          • patrickdrdP Offline
            patrickdrd
            last edited by

            ok, send me the first request to check and I’ll tell you what results I want omitted

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

              @patrickdrd

              ???

              1 Reply Last reply Reply Quote 0
              • patrickdrdP Offline
                patrickdrd
                last edited by

                what???

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

                  @patrickdrd

                  I’m certainly willing to assist, but I have no clue what “send me the first request to check and I’ll tell you what results I want omitted” means. (Which to me is the long form of my earlier response of “???”.)

                  1 Reply Last reply Reply Quote 2
                  • patrickdrdP Offline
                    patrickdrd
                    last edited by

                    thanks a lot,

                    I was talking about the original, first message,
                    ignore the follow-up for now,
                    we’ll talk about them after the initial results

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

                      Hello, @patrickdrd, @scott-sumner and All

                      Scott, I suppose that @patrickdrd was expecting your first regex attempt, in order to test it on real data ! However, I must admit that the @patrickdrd’s formulation looks like more as an imperative order than a polite request for some regex help :-(


                      Anyway, @patrickdrd, I’ll try to give you some hints !

                      Here is, below, the general form of the regex S/R which deletes all lines containing, exactly, n times the Char character ;-))

                      SEARCH ^(?:([^Char\r\n]*)Char){n}(?1)\R

                      REPLACE Leave EMPTY

                      In your case, as you, probably, want to delete all lines containing, exactly, 1 hash char, only, whatever its location, the correct regex becomes :

                      ^(?:([^#\r\n]*)#){1}(?1)\R

                      which can be shortened as :

                      ^([^#\r\n]*)#(?1)\R

                      Notes :

                      • The [^#\r\n]* part represents the longest range, even null, of characters different from # and line-breaks, stored as group 1 and re-used, after the # symbol, in the (?1) sub-routine call syntax, which is equivalent to [^#\r\n]*

                      • As usual, the \R form matches any line-break, whatever the file type ( Windows, Unix or Mac )

                      Cheers,

                      guy038

                      Scott SumnerS 1 Reply Last reply Reply Quote 2
                      • patrickdrdP Offline
                        patrickdrd
                        last edited by

                        sorry guys, I didn’t mean to be impolite, I just didn’t express myself properly

                        1 Reply Last reply Reply Quote 1
                        • patrickdrdP Offline
                          patrickdrd
                          last edited by

                          ok, I’ve just tested guy038’s suggestion and it’s not “safe” because
                          it matches these lines I would like excluded:

                          @@.jpg#$image,domain=comando-filmes.org
                          @@.png#$image,domain=fbfriendrequest.com|igflash.com|likesgroup.com
                          ||mexashare.com^*.png#$image,domain=mexashare.com,redirect=2x2-transparent.png
                          *.png#$image,redirect=2x2-transparent.png,domain=idsly.com
                          *.png#$image,redirect=2x2-transparent.png,domain=premiumtoss.com
                          *.jpg#$image,redirect=2x2-transparent.png,domain=300mbfilms.org
                          *.png#$image,redirect=2x2-transparent.png,domain=golrojadirecta.com
                          *.gif#$image,redirect=1x1-transparent.gif,domain=totaldebrid.org
                          .png#$image,domain=boveda7k.es,redirect=2x2-transparent.png
                          @@
                          .png#$image,domain=driverdestek.com
                          *.jpg#$image,domain=radiocockpit.fr,redirect=3x2-transparent.png
                          *.gif#$image,domain=vertdtgratis.es,redirect=1x1-transparent.gif

                          so maybe my best shot is #\s

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

                            @guy038 said:

                            the (?1) sub-routine call syntax

                            Gotta love the sub-routine syntax…why write something like [abc]{5} when you can write (?+1)(?'name'[abc])(?1)(?-1)(?&name) ? :-D

                            Example shamelessly stolen from here after I read up on it…and OK, that example includes named groups as well…but all good stuff (that works in N++).

                            1 Reply Last reply Reply Quote 1
                            • Scott SumnerS Offline
                              Scott Sumner @patrickdrd
                              last edited by Scott Sumner

                              @patrickdrd

                              Hey, you’ve been around long enough to know to indent every line of example text with 4 spaces before posting. :-)

                              (Noticed that you escaped some * but apparently not all because some of your text is in italics…way easier to just indent 4 and forgetaboutit)

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

                                Hi, @patrickdrd, @scott-sumner and All

                                Scott, your regex use of the (?1) syntax made me laugh a lot ;-)) Of course, it would be ridiculous to use such a regex !

                                So, the generic regex S/R, of my previous post, which deletes all lines containing, exactly, n times the Char character can, also, be written :

                                SEARCH ^(?:[^Char\r\n]*Char){n}[^Char\r\n]*\R?

                                REPLACE Leave EMPTY


                                Now, generally speaking, when you want to delete some lines of a file, based on a criteria, just determine :

                                • The common characteristics of all the lines which have to be to kept

                                OR the opposite :

                                • The common characteristics of all the lines which have to be deleted

                                patrickdrd, reading more carefully, and from your last example, it’s seemed that you would like to delete, either :

                                • All lines, containing the #$ string

                                • All lines, containing more than one hash character #

                                In that case, use the regex S/R, below :

                                SEARCH ^.*#(.*#|\$).*\R?

                                REPLACE Leave EMPTY

                                Cheers,

                                guy038

                                1 Reply Last reply Reply Quote 0
                                • patrickdrdP Offline
                                  patrickdrd
                                  last edited by

                                  no, sexually l actually I want to keep those lines and the ones posted above, it’s an awkward one, I know

                                  1 Reply Last reply Reply Quote 1
                                  • patrickdrdP Offline
                                    patrickdrd
                                    last edited by

                                    damn auto correct…

                                    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