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