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

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Masutin
Posts: 2
Joined: Tue Jul 23, 2024 11:53 pm

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

Post 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?
Last edited by AmigoJack on Thu Jul 25, 2024 7:51 am, edited 1 time in total.
Reason: formatting
User avatar
AmigoJack
Posts: 532
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

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

Post 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.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

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

Post 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.
Masutin
Posts: 2
Joined: Tue Jul 23, 2024 11:53 pm

Post 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
User avatar
bbadmin
Site Admin
Posts: 878
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

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

Post 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.
Post Reply