Question about lookup {...}

I’m trying to figure out how to make this replacement:

sub t h e by t_h_e;

but only if it is surrounded by “space” characters.
In other words, the replacement shouldn’t work in, for example, in word “therefore”.
I’ve tried the following (in calt function) but it doesn’t seem to work:

lookup THE {
	ignore sub @Anyletter t h e @Anyletter;
	sub t h e by t_h_e;
} THE;

I guess the issue is that I’m not marking “t h e” as something that needs to be “ignored” by the function… Any thoughts how it might be done?

Or the only way to achieve this would be creating ligature space_t_h_e_space?

The code should be:

ignore sub @AnyLetter t' h' e', t' h' e' @AnyLetter;

Take a look at the positional alternates tutorial.

Unfortunately, that doesn’t work either…

lookup THE {
ignore sub @Anyletter t' h' e', t' h' e' @Anyletter;
sub t h e by t_h_e;
} THE;

Will take another look at the tutorial, thank you!

@elena you need to mark the glyph sequence:

lookup THE {
    ignore sub @Anyletter t' h' e', t' h' e' @Anyletter;
    sub t' h' e' by t_h_e;
} THE;

Tried that before i posted my message - it didn’t work. Now it works.
Thank you one more time!