regexp with hashes help

  • what???

  • @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 “???”.)

  • 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

  • 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


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


    which can be shortened as :


    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 )



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

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


    so maybe my best shot is #\s

  • @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++).

  • @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)

  • 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?


    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?




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

  • damn auto correct…

Log in to reply