On 05/25/2021, at 19:17, Duncan Thorne <[email protected] 
<mailto:[email protected]>> 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 "[email protected]" 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/A4B22EA0-D109-4D69-8203-C6700A9622FC%40gmail.com.

Reply via email to