Off-topic posts of interest to the "Everything" community.
NotNull
Posts: 5461 Joined: Wed May 24, 2017 9:22 pm
Post
by NotNull » Tue May 19, 2020 1:35 pm
Context: Working on an AutoHotKey script in Notepad++ (meaning PCRE regex syntax)
In this script are quite a few (700) comment lines and empty lines (possibly including some spaces and tabs).
AHK comment lines start with a ";"
I can find them with:
How can I find the remaining (350) lines of code?. I should know this, but at this moment ...
therube
Posts: 4972 Joined: Thu Sep 03, 2009 6:48 pm
Post
by therube » Tue May 19, 2020 3:36 pm
Not sure what you're asking?
You want to find them all using NP++?
Looks like it would be, 'Find All in Current Document', but you know that. So... ?
ovg
Posts: 294 Joined: Thu Oct 27, 2016 7:19 pm
Post
by ovg » Tue May 19, 2020 3:43 pm
NotNull
Posts: 5461 Joined: Wed May 24, 2017 9:22 pm
Post
by NotNull » Tue May 19, 2020 4:23 pm
Thanks! Unfortunately that didn't work. It still finds all the lines I
don't want (but does that well).
A double negative lookahead (if that is the right terminology) does work (I'm a little less "groggy" now
):
therube
Posts: 4972 Joined: Thu Sep 03, 2009 6:48 pm
Post
by therube » Tue May 19, 2020 4:30 pm
Maybe this will give you non-empty,
^.*\S+
.
NotNull
Posts: 5461 Joined: Wed May 24, 2017 9:22 pm
Post
by NotNull » Tue May 19, 2020 5:16 pm
therube wrote: ↑ Tue May 19, 2020 3:36 pm
Not sure what you're asking?
Sorry; I was rather "groggy" when posting the question.
Script:
Code: Select all
<space><tab>; comment<CRLF>
<tab><tab><CRLF>
code1<CRLF>
<tab>code2<CRLF>
; comment<CRLF>
<tab><tab><CRLF>
The search (indeed, using 'Find All in Current Document') should report only both code lines.
Solution: the lookahead approach. Search for:
ovg
Posts: 294 Joined: Thu Oct 27, 2016 7:19 pm
Post
by ovg » Tue May 19, 2020 5:31 pm
Strange, I tested with regex101.com and RegexBuddy - working fine... It seems this is NP++ fault
NotNull
Posts: 5461 Joined: Wed May 24, 2017 9:22 pm
Post
by NotNull » Tue May 19, 2020 5:44 pm
ovg wrote: ↑ Tue May 19, 2020 5:31 pm
Strange, I tested with regex101.com and RegexBuddy - working fine... It seems this is NP++ fault
Compare this:
2020-05-19 19_39_25-Online regex tester and debugger_ PHP, PCRE, Python, Golang and JavaScript.png (18.16 KiB) Viewed 24316 times
with this:
2020-05-19 19_37_57-Online regex tester and debugger_ PHP, PCRE, Python, Golang and JavaScript.png (17.49 KiB) Viewed 24316 times
The first one isreporting all the non-code lines, the second one all the code lines.
I bet this is all a misunderstanding due to my poor descriptiom
I wanted to see only the code-lines.
(added .* to both expressions for better visibility).
ovg
Posts: 294 Joined: Thu Oct 27, 2016 7:19 pm
Post
by ovg » Tue May 19, 2020 6:22 pm
Ok
RegexNinja
Posts: 18 Joined: Sat Apr 11, 2020 2:45 pm
Post
by RegexNinja » Sun Jun 07, 2020 11:55 am
If it helps readability, you can always throw ORs into the LookAhead with \s.
^(?!\s*;| \s*$) should give the same results.
NotNull
Posts: 5461 Joined: Wed May 24, 2017 9:22 pm
Post
by NotNull » Sun Jun 07, 2020 3:07 pm
Nice!
I had mixed results in the past with using \s [1], so on auto-pilot I use an alternative. But in this case it fits well.
[1] Can't remember where and when. Maybe even a different regex flavour.