Using Highlighters pattern

Lets say for example I have a note with the following text

<link name="prototype" color="#993333" required="true" />

What I want is for highlighters to only highlight the word prototype.

How would I do this using a custom Highlighter note. Currently I am using

pattern: "(\w+)"
    case-sensitive: NO
    color: bright red

but this is highlighting everything that is within the double quotes. In the example above here is what I get,

image
which is not what i want

This is what I want
image

Is this possible?

Thanks in advance
Tom

The literal pattern:

pattern: "prototype"

Resulting the quotes being highlighted. So you need a ‘positive look-behind’ group before your literal string and a ‘positive look-ahead’ group after your literal string. Thus:

pattern: (?<=")prototype(?=")
	case-sensitive: NO
	color: bright red

The result:

So, ‘prototype’ or ‘Prototype’ are matched but only if proceeded and followed by straight double quotes.

Edit: note the extra regex need to be non-capturing groups to ensure the quotes aren’t coloured.

1 Like

One other thought. I’m not an expert here, but from what I do know of regex I assume these look-ahead/behind commands are at the more computationally expensive end of regex work. No big deal on a high-end Mac running the highlighter on a few notes. Low end Mac and 100s of such notes—perhaps not. Just something to bear in mind. I’ve learned to remember to consider scale as well as just completing the task at hand.

The above doesn’t imply Tinderbox is slow—it absolutely isn’t!

1 Like

Awesome… learned something today re: “positive look-behind” and “positive look-ahead”

Tom

" from what I do know of regex I assume these look-ahead/behind commands are at the more computationally expensive end of regex work."

No worries. I have a custom Highlighters note with <5 notes attached to it.

Tom

1 Like

Wonderful. So please forgive me what might seem presumptive implied critique. :slight_smile:

Not at all, it was a good reminder
Thanks Mark

1 Like