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 <dunc...@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: <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/1fa27e57-bc0b-4afe-9fb1-98c6d620a23en%40googlegroups.com.

Reply via email to