This depends on your data, but you might want to add a small addition to your regex patterns: add the check for other number on other side of X to avoid issues where you would just have something like "1Xa"
Names Default To Here(1);
strs = {"A1X2", "A1Xa", "1X2", "a1X23", "aX2", "A1X2a"};
For Each({str}, strs,
a1 = Regex(str, "(\d+)X", "\1");
a2 = Regex(str, "X(\d+)", "\1");
// vs
b1 = Regex(str, "(\d+)X(\d+)", "\1");
b2 = Regex(str, "(\d+)X(\d+)", "\2");
Write("\!NCurrent string: ", str);
Write("\!NFirst pattern matches: ", a1, " ", a2);
Write("\!NSecond pattern matches: ", b1, " ", b2);
Write("\!N");
);
Current string: A1X2
First pattern matches: 1 2
Second pattern matches: 1 2
Current string: A1Xa
First pattern matches: 1 .
Second pattern matches: . .
Current string: 1X2
First pattern matches: 1 2
Second pattern matches: 1 2
Current string: a1X23
First pattern matches: 1 23
Second pattern matches: 1 23
Current string: aX2
First pattern matches: . 2
Second pattern matches: . .
Current string: A1X2a
First pattern matches: 1 2
Second pattern matches: 1 2
-Jarmo