Page 1 of 1

TextPad Help says regex $0 for selected text corresponds to & in old syntax but the Find function can't match it

Posted: Wed Jul 24, 2024 6:22 pm
by Masutin
Example:
  1. Not working.
    Find:

    Code: Select all

    $0
    Replace with:

    Code: Select all

    [$&]
    \& will still be matched in new syntax, only for text without line breaks.
  2. Old syntax.
    Find:

    Code: Select all

    \&
    Replace with:

    Code: Select all

    [&]
P.S. No folding functions in TextPad?

Re: TextPad Help says regex $0 for selected text corresponds to & in old syntax but the Find function can't match it

Posted: Thu Jul 25, 2024 8:00 am
by AmigoJack
Masutin wrote: Wed Jul 24, 2024 6:22 pmregex $0 for selected text corresponds to & in old syntax but the Find function can't match it
Isn't the whole sense of $0 to be used in a potential replacement instead of a finding? Just like $1, $2, $3 etc. are used for groupings in the match? Using $0 means the whole matching regex without any groupings, so using it to find anything becomes logically impossible, since it would refer to itself.
Masutin wrote: Wed Jul 24, 2024 6:22 pmReplace with:

Code: Select all

[$&]
I did my best to format your post despite your settings to not parse any BBCode (mainly because then it's less ambiguous what your actual regex/replacement should be, secondly to have a true list) - is this the replacement you really wanted? An opening square bracket, then your whole match, then a closing square bracket?
Masutin wrote: Wed Jul 24, 2024 6:22 pmNo folding functions in TextPad?
Yes: such a feature does not exist. In contrast to f.e. Notepad++ TextPad can handle very big files and use search & replace on those in a timely manner, while Notepad++ takes a very long time. Folding lines surely comes with a performance impact somewhere, and I'm glad TextPad doesn't have it so far.

Re: TextPad Help says regex $0 for selected text corresponds to & in old syntax but the Find function can't match it

Posted: Thu Jul 25, 2024 1:11 pm
by ben_josephs
As AmigoJack writes, using $0 in a search expression makes no sense.
It matches the end of a line ($) followed by a "0". But that sequence exists nowhere, as the end of a line is followed by a newline character sequence (1 or 2 characters).

Keep in mind that regexes and replacements are entirely different things and have different syntaxes.

Posted: Thu Jul 25, 2024 6:15 pm
by Masutin
Thanks for your replies!
If you please could suggest a replacement expression for putting, say, brackets around (a few lines of) selected text. Or just a find string to match any selected text.
Sorry for unintended confusion. I looked for an alternative to \& in a wrong place:
Replacement Format Syntax Conversion
Old & (probably the POSIX syntax used prior to TextPad 7)
Perl/JavaScript $0

Re: TextPad Help says regex $0 for selected text corresponds to & in old syntax but the Find function can't match it

Posted: Thu Jul 25, 2024 7:41 pm
by bbadmin
If you lookup Perl Modifiers in the section on Regular Expression Syntax in the help file, it explains how to match over multiple lines using "(?s)". Hence, to quote a multi-line string, select it then:

Find what: (?s).+
Replace with: "$0"
Replace All in Selected Text.