Representing the complement of a previous capture in string patterns

Is it possible to represent the complement of a previous capture in a string pattern?

For example,
^((.)%2)$
This pattern will only match when the second character is equal to the first character.
What I’m trying to achieve is having the pattern only match when the second character is not equal to the first character.
I’ve tried using character sets
^((.)[^%2])$" (didn’t work)
and frontier patterns
^((.)%f[^%2].)$ (didn’t work)
I could do this by simply putting the first character inside of the pattern, but I’m looking for a solution using only patterns.

local function set(x)
    return string.match(x,string.format("^((.)[^%s])$",string.sub(x,1,1)))
end
local function frontier(x)
    return string.match(x,string.format("^((.)%%f[^%s].)$",string.sub(x,1,1)))
end