Hi Tim,

As far as I understand it, BBLMKeywordPatterns are matched against 
individual words composed of characters in the <Identifier and Keyword 
Character Class> or <Identifier and Keyword Characters>.

As a consequence the ^ anchor in a BBLMKeywordPatterns is sort of 
equivalent to \b and will always match at the start of a word. 
Start of line for an individual word doesn't make much sense.

(*Please Rich or Patrick, correct me if I am wrong*)

You could kind of achieve what you are looking for by including the '%' and 
':' characters in the <Identifier and Keyword Character Class> and matching 
in the BBLMKeywordPatterns with:

    keyword: 
    
and 

    %keywordtwo:
    
Watch out though that those sequences might be present in some other 
unwanted positions in the text, for example at the end of a line before a 
bullet list.

Another solution could be to use the <Keyword Pattern> which is matched 
against the text of the document and thus can detect ^ anchors at the start 
of lines.

    ...
    <key>Language Features</key>
    <dict>
    ...
    <key>Keyword Pattern</key>
        <string><![CDATA[(?x)
(
    ^keyword(?=:)
|
    ^%keywordtwo(?=:)
)
]]></string>
    ...
    <dict/>
    ...
    
HTH

Jean Jourdain

On Tuesday, February 15, 2022 at 4:44:59 PM UTC+1 Tim Gray wrote:

> I have a question about defining keyword pattern matching in codeless 
> language modules using BBLMKeywordPatterns. Can a pattern be defined to 
> match only words at the beginning of a line? I’m not having much success 
> using the standard ^ regular expression.
>
> To give context, I’d like to define two types of run kinds. Both are 
> always at the beginning of a line and end with a colon; one also leads off 
> with a %. Example:
>
> Keyword: do not match anything after the colon
> %keywordtwo: don’t match this either
>
> Thanks
> Tim
>
>
>

-- 
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/89ea7013-1814-44f6-abde-3ef03aaeefa8n%40googlegroups.com.

Reply via email to