• Login
Community
  • Login

regexp with hashes help

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
regexregex
16 Posts 3 Posters 2.8k 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.
  • P
    patrickdrd
    last edited by Nov 20, 2018, 3:19 PM

    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
    • P
      patrickdrd
      last edited by Nov 20, 2018, 3:25 PM

      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

      S 1 Reply Last reply Nov 20, 2018, 6:56 PM Reply Quote 0
      • S
        Scott Sumner @patrickdrd
        last edited by Nov 20, 2018, 6:56 PM

        @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
        • P
          patrickdrd
          last edited by Nov 20, 2018, 9:54 PM

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

          S 1 Reply Last reply Nov 21, 2018, 1:25 AM Reply Quote 0
          • S
            Scott Sumner @patrickdrd
            last edited by Nov 21, 2018, 1:25 AM

            @patrickdrd

            ???

            1 Reply Last reply Reply Quote 0
            • P
              patrickdrd
              last edited by Nov 21, 2018, 6:31 AM

              what???

              S 1 Reply Last reply Nov 21, 2018, 1:09 PM Reply Quote 0
              • S
                Scott Sumner @patrickdrd
                last edited by Nov 21, 2018, 1:09 PM

                @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
                • P
                  patrickdrd
                  last edited by Nov 21, 2018, 1:46 PM

                  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
                  • G
                    guy038
                    last edited by Nov 21, 2018, 1:56 PM

                    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

                    S 1 Reply Last reply Nov 21, 2018, 8:23 PM Reply Quote 2
                    • P
                      patrickdrd
                      last edited by Nov 21, 2018, 2:02 PM

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

                      1 Reply Last reply Reply Quote 1
                      • P
                        patrickdrd
                        last edited by Nov 21, 2018, 8:21 PM

                        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

                        S 1 Reply Last reply Nov 21, 2018, 8:28 PM Reply Quote 0
                        • S
                          Scott Sumner @guy038
                          last edited by Nov 21, 2018, 8:23 PM

                          @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
                          • S
                            Scott Sumner @patrickdrd
                            last edited by Scott Sumner Nov 21, 2018, 8:29 PM Nov 21, 2018, 8:28 PM

                            @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
                            • G
                              guy038
                              last edited by guy038 Nov 22, 2018, 1:37 AM Nov 21, 2018, 10:47 PM

                              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
                              • P
                                patrickdrd
                                last edited by Nov 21, 2018, 11:14 PM

                                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
                                • P
                                  patrickdrd
                                  last edited by Nov 21, 2018, 11:46 PM

                                  damn auto correct…

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