about selection
-
Three reasons I can think of:
Error prevention
. Regex provides more control than the normal mode, so I can make sure to only match what it is needed —as I haven’t checked the actual file and as I only had seen a sample—, I don’t know if those three hashes are also located in the middle of the file.More error prevention
. Regex also provides a way to override options that the user inadvertently may have checked. Thus, in the last regex(?s)
forces the regex to run a multiline search.Personal habit
. In myNotepad++
the regex mode is always checked, so my first attempt is to run even simple searches in that mode. I only select the normal mode in order to avoid regex metacharacters intrusion — and get back to regex realm as soon as possible :)
-
@astrosofista said in about selection:
I only select the normal mode in order to avoid regex metacharacters intrusion — and get back to regex realm as soon as possible
Or you could just stay permanently in the regex realm (Search mode = Regular expression) and just lead off any “normal” searches you need to do (because of metacharacters) with a quick
\Q
– no need to bother with a trailing\E
! :-)You can’t do a Whole word search this way, though, if you ever use that option, because that checkbox is disabled (but you could go to the trouble of adding
\b
before the\Q
and at the other end). -
@astrosofista said:
…didn’t noticed till now that italics being applied after the * — maybe we need an escape character for avoid that
I think maybe we have a misunderstanding. Your regexes in this thread are fine, I was just suggesting
this method
instead of
this method
because the second method does some lexing (does it think it is C++ above because it has special highlighting for “this”?) and the first method just leaves everything alone (and thus is probably clearer).
-
@Alan-Kilborn said in about selection:
I think maybe we have a misunderstanding. Your regexes in this thread are fine, I was just suggesting…
Oh, yes. I thought you were suggesting
inline
regexes —that is, regular expressions in the middle of a paragraph—, which I really found confusing unless the expression is limited to a few characters.So it´s clearer now. I will preserve the message structure while avoiding the multicolored format.
-
@Alan-Kilborn said in about selection:
Or you could just stay permanently in the regex realm…
Hmm, it looks very interesting. Will check the documentation, thank you.
Concerning the whole word issue, it wouldn’t necessarily be a problem. Because the
Matching Brace
feature is not available in theFind
panel, a tool that I find almost indispensable to handle complex regexes, and both theSearch
andReplace
fields are really short and the font size is too small for my needs, I usually write expressions on theEditor
and use hotkeys to import and export them, so adding one or two options may not represent much trouble.But let me first read about it and see if I can adapted it to my ways.
-
Hello, @cisco779k, @alan-kilborn, @astrosofista, and All
Of course, you certainly know that, in order to insert a code block, you must use, either the syntaxes :
```
Code_Text
```or
~~~
Code_Text
~~~But, do you know that you can add an indication, after the opening
```
or~~~
, to force a nice visual aspect of a specific language ?Indeed, for example, you may use
```
c to display aC
code block,```
xml to visualize anXML
piece of code and```
py to show a nicepython
script !And to get only a black foreground text, with a white background, simply use any invalid indication. I usually write the
```
z syntax !
Here are, below, the different indications that I’ve found out, yet, from the language names and extensions used :
•---------------•--------------•---------------• | LANGUAGE | MAIN form | OTHER forms | •---------------•--------------•---------------• | bash | sh | bash | | c | c | h | | c++ | cpp | hpp | | c# | cs | | | CSS | css | | | DIFF | diff | patch | | HTML | html | xhtml | | HTTP | http | https | | ini file | ini | | | javaScript | js / jsx | java | | JSON | json | | | | jsp | | | Makefile | mk / mak | makefile | | Objective-C | mm | objectivec | | Perl | pl / pm | perl | | php | php | php3 / php4 | | Python | py | python | | Ruby | rb | ruby | | SQL | sql | | | XML | xml | xsl | •---------------•--------------•---------------•
Note that I’m not sure, exactly, to which languages (
Java
,JavaScript (embedded)
,JavaScript
) refer the indications js and jsp !?Best Regards,
guy038
-
@guy038 said in about selection:
I usually write the ```z syntax
I always wondered why the
z
was included, and sometime between last year and now, I had dropped thez
to become just```
alone. Now that I know the purpose of thez
(and the other options), I’ll have to start using those.And if you use the
</>
button to fomat a block of text, you can still go back above and add in the option; for example, here I addedpl
to the```
line after I generated it using</>
.my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
yep, it properly highlights that. cool.
edits: fixed incomplete sentences/thoughts.
-
Hello, @cisco779k, @alan-kilborn, @astrosofista, @peterjones and All,
Oh…, I’m sorry ! I spoke a little too fast :-(( Peter, I did some tests, again, with your piece of
Perl
, aPython
script, someHTML
andC
code and…, seemingly, as soon as you click on the</>
icon and you paste the different pieces of code,NodeBB
seems, each time, to detect correctly the language !?Indeed, after I added the related indication, and used
Ctrl + Z
andCtrl + Y
, I did not be able to see any difference in the code !!So, the table shown, in my previous post, is rather useless. The only interesting case would be if you would show for instance, a
Perl
script, with thePython
syntax !Could your confirm my tests ?
Cheers,
guy038
-
@guy038, @cisco779k, @alan-kilborn, @PeterJones, All
Thank you for sharing this interesting and useful info. And also can be mixed!
I played a bit with the available options and selected two alternative ways (
js
andmk
) to the usual one to display regexes:Search: (?s)[^#]+\R\K.*?(?=\R[^#]) Replace: [leave empty]
Search: (?s)[^#]+\R\K.*?(?=\R[^#]) Replace: [leave empty]
Search: (?s)[^#]+\R\K.*?(?=\R[^#])
Replace: [leave empty]
Both alternative displays are not multicolored and don’t mix font styles, so I think are fine. And aiming to create some contrast against text paragraphs, I am currently not sure but probably will use the second one. I hope @alan-kilborn won’t have strong opinions against it, ha ha.
@guy038, let me ask you a question: how do you create those nice tables? Is a free tool? I’m curious.
Best Regards
-
Could your confirm my tests ?
auto-identify:
my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
force
```pl
my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
force
```py
(purposefully wrong syntax)my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
force
```z
(blank)my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
indent
my $default; open my $fh, '>', 'out.txt' or die "Goodbye, cruel world: $!"; sub hehe { say "haha"; } BEGIN { $default = Win32::Mechanize::NotepadPlusPlus::Notepad->_new(); }
summary
yes, it auto-identifies if there’s nothing. But there are times when the text is ambiguous, or truly plaintext, so using the hardcoded filetype will enforce proper syntax highlighting in the forum.
ps
edit: sorry, @astrosofista , for hijacking your thread with this tangent.
-
@astrosofista said in about selection:
I hope @alan-kilborn won’t have strong opinions against it, ha ha.
Well… :-)
Do it the way you want, but IMO this would be a more proper way, from your examples:
Search:
(?s)[^#]+\R\K.*?(?=\R[^#])
Replace: [leave empty]It doesn’t muddy what one would copy for the search regex, and since “[leave empty]” isn’t a regex it shouldn’t be specially highlighted.
But, really, it is all pointless. Whatever gets your point across.
Lately my ideal way is this:
Find what box:
(?s)[^#]+\R\K.*?(?=\R[^#])
Backward direction checkbox: unticked
Match whole word only checkbox: unticked (and disabled)
Match case checkbox: unticked
Wrap around checkbox: unticked
Search mode radiobutton: Regular expression…because I have a script that grabs that data right off the Find window, and formats it.
-
@PeterJones said in about selection:
edit: sorry, @astrosofista , for hijacking your thread with this tangent.
Nothing to be sorry about, and for sure the info is quite relevant, so I am paying attention.
-
I get your points and I think they are quite reasonable. However and unfortunately I don’t clearly see the reddish text inside backtickets displayed on a black background —my better option—, so I feel the need to look for other color(s) to easy my reading.
Now, concerning your ideal way of extracting data from the Find window, I like the idea and depending on how much use I could give it, I will probably develop my own, thank you for the inspiration! :-)
Best Regards
-
@astrosofista said in about selection:
reverse all the lines between hashes and only those
@cisco779k said:
@ astrosofista
you understand what I want to do@cisco779k
I’m aware this problem has largely been solved but thought it an interesting enough exercise to see if another method could be obtained by keeping the file intact and not having to use a plugin or export lines to another file. I think I’ve come up with a solution. It’s not original, indeed I knew of anoher solution employing this technique provided by @guy038 some time ago to pad out numbers (right justify).So my regex is
Find What:(?-s)(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)?(^[^#]{3}.+\R)
Replace With:\9\8\7\6\5\4\3\2\1
So at the moment it cannot work with more than 9 lines grouped together, however the concept can be expanded to more lines. Each capture group will store a line if AND only if the lines doesn’t start with 3
#
characters. Then the Replace With field writes them back in reverse order. As some capture groups will be empty there will be nothing to write.The only proviso I have is that there must be (in the current form of the regex) a blank line at the bottom of the file. This allows the last line to be captured as part of a group.
my 2cents worth
Terry -
Hi @Terry-R, All
Clever idea, I like it. And what I like even more is that it is easy to communicate and to apply, just one step, a S/R replacement. My approach isn’t original as well, and it is really complex, as it involves the BetterMultiSelection plugin, Column Editor, and a macro that mechanizes a regex and a sort to reverse the lines.
However, your method has a curious drawback, as you constraint it to only 9 groups. The good news is that there is no reason to stop here.
Don’t know if I’m guessing too much, but I suspect you were misguided by a syntactic issue, as replacements use the backslash
\
. I don’t remember where I learn about it, but it is possible to create up to 99 replacement groups, as long as the dollar$
sign is used in them. Hope I am not wrong about this, @guy038 surely knows all the details.As a test, just add two more groups to the Search field, and enter
($11)($10)$9$8$7$6$5$4$3$2$1
in the Replace box. Worked nice in this sample:### one one one one two two two two three three three three four four four four five five five five six six six six seven seven seven seven eight eight eight eight nine nine nine nine ten ten ten ten eleven eleven eleven eleven ### eleven eleven eleven eleven ten ten ten ten nine nine nine nine eight eight eight eight seven seven seven seven six six six six five five five five four four four four three three three three two two two two one one one one ###
Best Regards
-
@astrosofista said in about selection:
as you constraint it to only 9 groups.
Actually I did mention it could be extended and whilst not entirely familiar with the syntax I am aware of the possibility.
The examples provided only went to 5 or so lines so felt no need to get too complex. As I said a solution had been found and this was partly an exercise in testing my idea as it was different. Possibly it might pay, if OP wants to utilise this idea to first find a method to count max number of lines in any group. That is another question to be answered. I did have a regex which can do it, but it was not elegant.Terry
-
tanxs Terry! your reg-ex work fine for my intent! tanxs so much.
the rest of the discussion went a little off topic … should be moved to a separate post … anyway thanks to everyone for your attention. -
in reality i would just like to invert the first with the last line, in any
###
field -
@cisco779k said in about selection:
in reality i would just like to invert the first with the last line
I’m disappointed, not so much that my solution doesn’t now work as that you have totally changed the problem!
You aren’t the first to pull this stunt and likely won’t be the last but at the moment it is late evening for me so I’m not inclined to bust out my PC just to solve your new problem.Terry
-
Hello, @astrosofista and All,
In a previous post of that discussion, you said :
@guy038, let me ask you a question: how do you create those nice tables? Is a free tool? I’m curious.
Well, in fact, I don’t use any specific tool ! Just the usual column mode editor, with the help, mainly, of
3
characters only :-
The Hythen-Minus sign
-
-
The Equals sign
=
-
The Bullet sign
•
I personally like the Bullet sign because it is exactly vertically centered ;-)) It’s Unicode code-point is
\x{2022}
. Refer to :http://www.unicode.org/charts/PDF/U2000.pdf
Most of the time, you can get it with the keyboard sequence :
-
Hold down the
Alt
key -
Hit, successively, on keys
0
,1
,4
and9
of the numeric keypad -
Release the
Alt
key
Tables composed with that character look better than using the Asterisk sign (
*
) or the Full Stop/Dot char (.
). See, examples below :•---------------•--------------•---------------• *---------------*--------------*---------------* .---------------.--------------.---------------. | LANGUAGE | MAIN form | OTHER forms | | LANGUAGE | MAIN form | OTHER forms | | LANGUAGE | MAIN form | OTHER forms | •---------------•--------------•---------------• *---------------*--------------*---------------* .---------------.--------------.---------------. | bash | sh | bash | | bash | sh | bash | | bash | sh | bash | | | | | | | | | | | | | | c | c | h | | c | c | h | | c | c | h | | c++ | cpp | hpp | | c++ | cpp | hpp | | c++ | cpp | hpp | | c# | cs | | | c# | cs | | | c# | cs | | | CSS | css | | | CSS | css | | | CSS | css | | | | | | | | | | | | | | | DIFF | diff | patch | | DIFF | diff | patch | | DIFF | diff | patch | •---------------•--------------•---------------• *---------------*--------------*---------------* .---------------.--------------.---------------. •===============•==============•===============• *===============*==============*===============* .===============.==============.===============. | LANGUAGE | MAIN form | OTHER forms | | LANGUAGE | MAIN form | OTHER forms | | LANGUAGE | MAIN form | OTHER forms | •===============•==============•===============• *===============*==============*===============* .===============.==============.===============. | bash | sh | bash | | bash | sh | bash | | bash | sh | bash | |---------------•--------------•---------------| |---------------*--------------*---------------| |---------------*--------------*---------------| | c | c | h | | c | c | h | | c | c | h | | c++ | cpp | hpp | | c++ | cpp | hpp | | c++ | cpp | hpp | | c# | cs | | | c# | cs | | | c# | cs | | | CSS | css | | | CSS | css | | | CSS | css | | |---------------•--------------•---------------| |---------------*--------------*---------------| |---------------*--------------*---------------| | DIFF | diff | patch | | DIFF | diff | patch | | DIFF | diff | patch | •===============•==============•===============• *===============*==============*===============* .===============.==============.===============.
Best Regards,
guy038
-