regexp with hashes help
-
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,
ntimes the Char character ;-))SEARCH
^(?:([^Char\r\n]*)Char){n}(?1)\RREPLACE
Leave EMPTYIn your case, as you, probably, want to delete all lines containing, exactly,
1hash char, only, whatever its location, the correct regex becomes :^(?:([^#\r\n]*)#){1}(?1)\Rwhich can be shortened as :
^([^#\r\n]*)#(?1)\RNotes :
-
The
[^#\r\n]*part represents the longest range, even null, of characters different from#and line-breaks, stored as group1and re-used, after the#symbol, in the(?1)sub-routine call syntax, which is equivalent to[^#\r\n]* -
As usual, the
\Rform 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,
ntimes 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 EMPTYCheers,
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…
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