regexp with hashes help
-
what???
-
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
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 group1
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
-
-
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:@@.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.gifso 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)
? :-DExample 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++).
-
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?
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
-
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…