Re: Handling dollar signs in search and replace

2021-05-28 Thread Patrick Woolsey
Good afternoon folks and just a gentle reminder that this thread 
is drifting rather far afield for relevance... ;-)



Regards

 Patrick Woolsey
==
Bare Bones Software, Inc. 




On 5/28/21 at 12:34 PM, duncan...@gmail.com (Duncan Thorne) wrote:


Hi Chris,

Many thanks for the tip on Jedit Ω (used the Tex-Edit Plus special chars popup for 
"Ω").


[... details elided ...]

--
This is the BBEdit Talk public discussion group. If you have a feature request or need 
technical support, please email "supp...@barebones.com" rather than posting here. 
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/r480Ps-10146i-D2CD3C472D80451FBABD5A51A1C15B94%40Cylinder.local.


Re: Handling dollar signs in search and replace

2021-05-28 Thread Duncan Thorne
Hi Chris,

Many thanks for the tip on Jedit Ω (used the Tex-Edit Plus special chars popup 
for "Ω"). I've downloaded the Jedit web edition and  will be poking around in 
it. So, from Texas to Japan. Of course you risk questions about using 
Applescript with it! Not sure the BBedit forum would be thrilled. So far I’ve 
managed to tell Jedit Ω to activate. A start. I notice $20 Canadian to unlock 
the full find capabilities. Does it allow wildcard searches (and handle $ in 
the friendly scripting-for-the-rest-of-us Tex-Edit way), I wonder.

Great that Tom got a family, etc. and I wish him well — although it’s a pity he 
didn’t convert T-E+ to 64-bit first 浪. Priorities!

Cheers,
Duncan


> On May 27, 2021, at 5:50 PM, Christopher Stone  
> wrote:
> 
> On 05/26/2021, at 21:42, Duncan Thorne  > wrote:
>> I just noticed that you too use T-E+. I sing the praises of it every day and 
>> it's a big reason I'm still at Mojave, the last 32-bit compatible version of 
>> the OS. I wonder what happened to Tom Bender, the guy behind it. I've found 
>> no answer on Google.
> 
> 
> Hey Duncan,
> 
> I sent Tom a Christmas card in 2018 and had a brief email correspondence with 
> him.
> 
> It's the usual story – he got a job, had a family, and got busy...  :-)
> 
> In my opinion the only really viable replacement for Tex-Edit Plus is Jedit Ω 
> .
> 
> It doesn't have quite as organic a feel as Tex-Edit Plus, but it's similarly 
> powerful and relatively simple.
> 
> 
> --
> Take Care,
> Chris
> 
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a feature 
> request or need technical support, please email "supp...@barebones.com" 
> rather than posting here. Follow @bbedit on Twitter: 
> >
> --- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "BBEdit Talk" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/bbedit/xoorTiOkSCo/unsubscribe 
> .
> To unsubscribe from this group and all its topics, send an email to 
> bbedit+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/1A9EF0CB-9150-4936-9E11-3B331BAEA1A3%40gmail.com
>  
> .

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/80259189-DB32-46BE-9693-92475CD1CB54%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-27 Thread Christopher Stone
On 05/26/2021, at 21:42, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> I just noticed that you too use T-E+. I sing the praises of it every day and 
> it's a big reason I'm still at Mojave, the last 32-bit compatible version of 
> the OS. I wonder what happened to Tom Bender, the guy behind it. I've found 
> no answer on Google.


Hey Duncan,

I sent Tom a Christmas card in 2018 and had a brief email correspondence with 
him.

It's the usual story – he got a job, had a family, and got busy...  :-)

In my opinion the only really viable replacement for Tex-Edit Plus is Jedit Ω 
.

It doesn't have quite as organic a feel as Tex-Edit Plus, but it's similarly 
powerful and relatively simple.


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1A9EF0CB-9150-4936-9E11-3B331BAEA1A3%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-27 Thread Duncan Thorne
Hi Chris,
I just noticed that you too use T-E+. I sing the praises of it every day 
and it's a big reason I'm still at Mojave, the last 32-bit compatible 
version of the OS. I wonder what happened to Tom Bender, the guy behind it. 
I've found no answer on Google.
Cheers,
Duncan

On Wednesday, May 26, 2021 at 4:30:08 PM UTC-6 listmei...@gmail.com wrote:

> On 05/25/2021, at 23:19, Duncan Thorne  wrote:
>
> Here's a sample line from my script where things go wrong:
>
> *tell* *front* *text window's* *text*
>
> *replace* "2021
>
> \$" using " \$" options {search mode:*grep*, case sensitive:*false*, 
> starting at top:*true*} -- the idea being to take out a line break and 
> replace it with a tab.
>
> *end* *tell*
>
> --
>
> Hey Duncan,
>
> Backslash is the escape character in AppleScript, so when you need to 
> write it as a literal you have to *escape* the escape character.
>
> *set* myDollarSign *to* "\\$"
>
> I *know* this is often quite confusing to neophyte AppleScripters, so 
> please forgive me for forgetting to mention it explicitly.
>
> For future references here's how you'd write the regular expression 
> in AppleScript:
>
> *tell* *application* "BBEdit"
> *tell* *front* *document*
> *replace* "(2021)\\n(\\$)" using "\\1\\t\\2" options {search mode:
> *grep*, case sensitive:*false*, starting at top:*true*}
> *end* *tell*
> *end* *tell*
>
> If you take the literal strings (between the quotes) and replace the "\\" 
> with "\" as a literal string in BBEdit you'll get unescaped version 
> that BBEdit wants.
>
> A perhaps simpler trick to see the literal string is to copy it to the 
> clipboard like so:
>
> *set the clipboard to* "(2021)\\n(\\$)"
>
> --> (2021)\n(\$)
>
> The part after “--> ” is the pasted result.
>
> “--> ” is a writing convention for indicating the result of an AppleScript.
>
> I too am a long time user of Tex-Edit Plus and will sorely miss it down 
> the road.
>
>
> --
> Best Regards,
> Chris
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/9b1f60e2-998b-47c1-90d7-eabfbf036248n%40googlegroups.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread Christopher Stone
On 05/25/2021, at 23:19, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> Here's a sample line from my script where things go wrong:
> tell front text window's text
> 
> replace "2021
> 
> \$" using "   \$" options {search mode:grep, case sensitive:false, starting 
> at top:true} -- the idea being to take out a line break and replace it with a 
> tab.
> 
> end tell
> 


Hey Duncan,

Backslash is the escape character in AppleScript, so when you need to write it 
as a literal you have to escape the escape character.

set myDollarSign to "\\$"

I know this is often quite confusing to neophyte AppleScripters, so please 
forgive me for forgetting to mention it explicitly.

For future references here's how you'd write the regular expression in 
AppleScript:

tell application "BBEdit"
tell front document
replace "(2021)\\n(\\$)" using "\\1\\t\\2" options {search mode:grep, 
case sensitive:false, starting at top:true}
end tell
end tell

If you take the literal strings (between the quotes) and replace the "\\" with 
"\" as a literal string in BBEdit you'll get unescaped version that BBEdit 
wants.

A perhaps simpler trick to see the literal string is to copy it to the 
clipboard like so:

set the clipboard to "(2021)\\n(\\$)"

--> (2021)\n(\$)

The part after “--> ” is the pasted result.

“--> ” is a writing convention for indicating the result of an AppleScript.

I too am a long time user of Tex-Edit Plus and will sorely miss it down the 
road.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1D99E910-A13C-4F44-A723-43F76A17DE93%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread Duncan Thorne
It works! Also, much tidier. Thanks Rich for that, and to everyone else for 
all the hand holding. I can't thank you enough.

On Wednesday, May 26, 2021 at 7:12:21 AM UTC-6 sie...@barebones.com wrote:

> On 26 May 2021, at 0:19, Duncan Thorne wrote:
>
> > You are all a helpful bunch but I'm still sinking! I looked at the 
> > manual
> > and it addles my brain. Grep, zero-width positions, etc. Yikes.
>
> I think you'll find it simpler if you eliminate Grep from the process 
> and do a literal search. Try writing the "replace" operation in your 
> script as follows:
>
> replace "2021\\n$" using "2021\\t$" options {search mode:literal, case 
> sensitive:false, starting at top:true}
>
> ("\n" and "\t" are backslash character escapes for line break and tab, 
> respectively. The AppleScript editor will compile these into literal 
> characters, so to avoid this we add an extra backslash. If you don't do 
> that, the operation will still work, but the script is a little harder 
> to read.)
>
> R.
>
> -- 
> Rich Siegel Bare Bones Software, Inc.
>  
>
> Someday I'll look back on all this and laugh... until they sedate me.
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/8249aeb1-5193-447a-896e-75997ded75d9n%40googlegroups.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread Rich Siegel

On 26 May 2021, at 0:19, Duncan Thorne wrote:

You are all a helpful bunch but I'm still sinking! I looked at the 
manual

and it addles my brain. Grep, zero-width positions, etc. Yikes.


I think you'll find it simpler if you eliminate Grep from the process 
and do a literal search. Try writing the "replace" operation in your 
script as follows:


		replace "2021\\n$" using "2021\\t$" options {search mode:literal, case 
sensitive:false, starting at top:true}


("\n" and "\t" are backslash character escapes for line break and tab, 
respectively. The AppleScript editor will compile these into literal 
characters, so to avoid this we add an extra backslash. If you don't do 
that, the operation will still work, but the script is a little harder 
to read.)


R.

--
Rich Siegel Bare Bones Software, Inc.
  

Someday I'll look back on all this and laugh... until they sedate me.

--
This is the BBEdit Talk public discussion group. If you have a feature request or need 
technical support, please email "supp...@barebones.com" rather than posting here. 
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/6FBF850D-B1C2-4637-8F02-9D0E0C103C27%40barebones.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread Duncan Thorne
You are all a helpful bunch but I'm still sinking! I looked at the manual 
and it addles my brain. Grep, zero-width positions, etc. Yikes. My limited 
Applescript background has been mainly with the ancient 32-bit Tex-Edit 
Plus, which was somewhere between a text editor and a word processor 
(fonts!) and even I could vaguely understand it. BBEdit is obviously more 
for programmers, and I'm not used to the deep end. In any event with much 
help from you patient folks in the community I've got a BBEdit script that 
would work well for my simple needs — except with $ signs.
I've found that /$ doesn't seem to do anything, and \$ throws up a syntax 
error. (Expected “"” but found unknown token.) But perhaps I'm meant to use 
one form in the "find" part another in "replace"?
Here's a sample line from my script where things go wrong:

*tell* *front* *text window's* *text*

*replace* "2021

\$" using " \$" options {search mode:*grep*, case sensitive:*false*, 
starting at top:*true*} -- the idea being to take out a line break and 
replace it with a tab.

*end* *tell*

Much appreciation!
On Tuesday, May 25, 2021 at 9:39:27 PM UTC-6 listmei...@gmail.com wrote:

> On 05/25/2021, at 19:17, Duncan Thorne  wrote:
>
> I'm stumped when it comes to reformatting a text line that begins with a $ 
> symbol. I want to replace the preceding line's line break, followed by the 
> new line's $, with a tab-$.
> For instance:
> ... 2021
> $0.23
>
> changed to:
> ... 2021 (tab) $0.23
>
> --
>
> Hey Duncan,
>
> Look in Chapter 8 of BBEdit's User Manual: Searching with Grep (p182)
>
> (Available from the BBEdit Help Menu.)
>
> $ is a regex metacharacter referred to as an *anchor*, and it indicates 
> the end of a line.
>
> ^ (the caret character) refers to the beginning of a line.
>
> As Kerri mentions you *escape* these characters when using them 
> literally.  (This takes a little getting used to.)
>
> \ (backslash) is the usual escape character so – \$ and \^
>
> *Find:*
>
> \n^(\$\d+)
>
>
> \n  == linefeed
> ^   == beginning of line
> (   == start of capture group)
> \$  == literal dollar sign character
> \d  == digit
> +   == one or more
> )   == end of capture group
>
> *Replace:*
>
> \t\1
>
>
> \t == literal tab
> \1 == capture group 1
>
> This is your basic regular expression.
>
> --
>
> A more advanced regular expression using a positive lookahead assertion:
>
> *Find:*
>
> \n(?=\$)
>
>
> \n  == linefeed
> (   == start of a NON-capture group
> ?=  == lookahead assertion which looks for a string *without* selecting it
> \$  == literal dollar sign
> )   == close of the non-capture group
>
> *Replace:*
>
> \t
>
>
> \t == literal tab
>
> With this method and your use-case I don't have to capture any text and 
> put it back; I can just replace the found text with a tab.
>
> Many people think regular expression are cruel and unusual punishment, but 
> I enjoy them – they're fun (and sometimes also frustrating) puzzles to 
> solve.  
>
> --
> Best Regards,
> Chris
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1fa27e57-bc0b-4afe-9fb1-98c6d620a23en%40googlegroups.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread @lbutlr
On 25 May 2021, at 18:17, Duncan Thorne  wrote:
> I'm stumped when it comes to reformatting a text line that begins with a $ 
> symbol. I want to replace the preceding line's line break, followed by the 
> new line's $, with a tab-$.
> For instance:
> ... 2021
> $0.23
> 
> changed to:
> ... 2021 (tab) $0.23
> 
> BBEdit search-and-replace treats $ as a special search symbol, I gather to do 
> with matching. Is there a way to make it see $ as a dollar sign?

I won't repeat what everyone else has said, but a few other notes.

As a shortcut, whenever you see a RED characters in the bbedit search field 
that character is special, and throwing a \ in front of it will turn the pair 
blue, which means it will not be the special grep character but instead an 
escaped character.

\r is an escape for "return" character
\n which is an escape for a "newline" character

In nearly all BBEdit files, if not all, these are equivalent. This is not the 
case in all editors however.

If you go to the Search Menu and then "Pattern Playground" you will see threee 
items at the top next to the words "Search patter:" one looks like a g, one 
looks like a clock, and only looks like a ? In a circle. The last will show a 
long list of sample patters.

These same items appear int eh find/replace dialog, but the pattern playground 
is an excellent place to see what the expressions you are typing will match in 
the document, so I recommend starting there. It is very easy to then use the 
pattern for a find and replace.



-- 
When the routine bites hard / and ambitions are low And the
resentment rides high / but emotions won't grow And we're
changing our ways, / taking different roads Then love, love will
tear us apart again

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/AA3A1110-FA55-4D19-88DC-13AD9C74286E%40kreme.com.


Re: Handling dollar signs in search and replace

2021-05-25 Thread Christopher Stone
On 05/25/2021, at 19:17, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> I'm stumped when it comes to reformatting a text line that begins with a $ 
> symbol. I want to replace the preceding line's line break, followed by the 
> new line's $, with a tab-$.
> For instance:
> ... 2021
> $0.23
> 
> changed to:
> ... 2021 (tab) $0.23


Hey Duncan,

Look in Chapter 8 of BBEdit's User Manual: Searching with Grep (p182)

(Available from the BBEdit Help Menu.)

$ is a regex metacharacter referred to as an anchor, and it indicates the end 
of a line.

^ (the caret character) refers to the beginning of a line.

As Kerri mentions you escape these characters when using them literally.  (This 
takes a little getting used to.)

\ (backslash) is the usual escape character so – \$ and \^

Find:

\n^(\$\d+)


\n  == linefeed
^   == beginning of line
(   == start of capture group)
\$  == literal dollar sign character
\d  == digit
+   == one or more
)   == end of capture group

Replace:

\t\1


\t == literal tab
\1 == capture group 1

This is your basic regular expression.


A more advanced regular expression using a positive lookahead assertion:

Find:

\n(?=\$)


\n  == linefeed
(   == start of a NON-capture group
?=  == lookahead assertion which looks for a string without selecting it
\$  == literal dollar sign
)   == close of the non-capture group

Replace:

\t


\t == literal tab

With this method and your use-case I don't have to capture any text and put it 
back; I can just replace the found text with a tab.

Many people think regular expression are cruel and unusual punishment, but I 
enjoy them – they're fun (and sometimes also frustrating) puzzles to solve.  

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/A4B22EA0-D109-4D69-8203-C6700A9622FC%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-25 Thread Kerri Hicks
When using grep, $ anchors the match at the end of the line.

Add a slash before the $ to escape it, so it's used as a literal character.

--Kerri

On Tue, May 25, 2021, 9:15 PM Duncan Thorne  wrote:

> I'm stumped when it comes to reformatting a text line that begins with a $
> symbol. I want to replace the preceding line's line break, followed by the
> new line's $, with a tab-$.
> For instance:
> ... 2021
> $0.23
>
> changed to:
> ... 2021 (tab) $0.23
>
> BBEdit search-and-replace treats $ as a special search symbol, I gather to
> do with matching. Is there a way to make it see $ as a dollar sign?
>
> --
> This is the BBEdit Talk public discussion group. If you have a feature
> request or need technical support, please email "supp...@barebones.com"
> rather than posting here. Follow @bbedit on Twitter: <
> https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to bbedit+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bbedit/97b9fd3b-0139-442b-8cb5-9722c26b3802n%40googlegroups.com
> 
> .
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CAEmA4uaqZcm%3D09aTd7y5GJERPB3ROgogu62%2B-dNHydvkOhDamA%40mail.gmail.com.


Handling dollar signs in search and replace

2021-05-25 Thread Duncan Thorne
I'm stumped when it comes to reformatting a text line that begins with a $ 
symbol. I want to replace the preceding line's line break, followed by the 
new line's $, with a tab-$.
For instance:
... 2021
$0.23

changed to:
... 2021 (tab) $0.23

BBEdit search-and-replace treats $ as a special search symbol, I gather to 
do with matching. Is there a way to make it see $ as a dollar sign?

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/97b9fd3b-0139-442b-8cb5-9722c26b3802n%40googlegroups.com.