Hi Todd,

This applescript seems to do what you want :

*tell* *application* "BBEdit"

*try*

*tell* *first* *document* *of* *front* *window*

*set* vSelectionEnd *to* (characterOffset *of* *its* *window's* selection) 
- 1

*set* vRegex *to* "\\\\[A-Za-z0-9_ 
\\s]*(?:\\s+\"[^\"]*\")?\\s*(\\[(?:[^\\[\\]]+|(?1))*\\])(?:(\\s*=\\s*)(?P<function_name>[a-zA-Z0-9_!?]+))?"

*set* vOptions *to* {search mode:*grep*, wrap around:*false*, backwards:
*true*}

*set* vResult *to* *find* vRegex searching in *it* options vOptions

*if* vResult's found *then*

*set* vSelectionStart *to* characterOffset *of* vResult's found object

*else*

*error* "Pattern not found."

*end* *if*

*select* *its* *characters* vSelectionStart *thru* vSelectionEnd

*end* *tell*

*on* *error* aMessage number aErrorNumber

*if* aErrorNumber ≠ -128 *then* -- Error number -128 (User Cancelled).

*display dialog* aMessage

*else*

*return*

*end* *if*

*end* *try*

*end* *tell*

Successfully tested against those expressions (courtesy of Claude):

\section [main]

\config "default settings" [database] = connect

\path [logs]

\module [auth[user]] = login_handler

\service   [web_server] = nginx

\handler "error pages" [404[custom]] = not_found!

\backup     [files] = backup_job

\system [network[tcp[port]]] = handle_connections?

\data "user info"   [profiles] = user_manager

\temp [cache[memory[buffer]]] = cache_clear!


HTH,

Jean Jourdain
On Sunday, August 24, 2025 at 2:02:53 AM UTC+2 Todd Ingalls wrote:

> Hello,
> I am working on something in an esoteric language and have a Function 
> Pattern that works great 
> \\[A-Za-z0-9_ 
> \s]*(?:\s+"[^"]*")?\s*(\[(?:[^\[\]]+|(?1))*\])(?:(\s*=\s*)(?P<function_name>[a-zA-Z0-9_!?]+))?
>
> What I want to be able to do is from wherever my cursor is to search 
> backwards and find the beginning of this function definition and then 
> select all the text from where my cursor was to the beginning of the 
> function.
>
> I can use find previous  with the grep pattern and that will select that 
> function but not the text from where my cursor was. I can also use Reveal 
> Start in Go->Functions to move the cursor to the beginning of the previous 
> function. I just can't seem to figure out how to quite accomplish what I 
> want in AppleScript. Any thoughts would be appreciated
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or believe that the application isn't working correctly, please email 
"[email protected]" rather than posting here. Follow @bbedit on Mastodon: 
<https://mastodon.social/@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 visit 
https://groups.google.com/d/msgid/bbedit/d6ec7d50-afef-4339-a18e-71791f5cb216n%40googlegroups.com.

Reply via email to