[Question]
  [
In this challenge, you receive a string as input containing a string of X's, Y's and Z's eg. "XYZZ". X, Y and Z represent a particular character. This pattern is then compared with a second string input. If the pattern exists as a substring in the second input, return `True`, otherwise, return `False`. Once a pattern is found in the word, the program stops searching and returns `True`.
## Examples
Pattern: "XXYY"
```
succeed ---> True (pattern found: ccee)
success ---> False (pattern not matched)
balloon ---> True (pattern found: lloo)
```
Pattern: "XYXYZ"
```
bananas ---> True (pattern found: nanas)
banana  ---> False (pattern not found)
```
* Note: This is not the actual input. This is an example of how the program should work. Your program should output `True` or `False`, or other Truthy/Falsy values.
## Other important/useful information
* The pattern does not need to contain an X, Y and a Z, it could contain X's and Y's or even (although somewhat pointless) just X's.
* The pattern cannot be empty, but this will not be used as a test case.
* The search string will not be empty, and will be lowercase.
* The alphabetic order of X, Y and Z in the pattern does not matter.
* X, Y and Z *must* be unique characters.
* You may use any library you wish.
* The score is determined by the **code size**, in bytes. Lowest score wins.
Good luck!
  
[Answer]
# [Perl 5](https://www.perl.org/), 85 bytes
*Saved 40 bytes thanks to Peter Taylor's suggestion! (see my older version bellow to see the differences)*
83 bytes of code + `-pl` flag.
```
s/./$h{$&}?"\\$h{$&}":($h{$&}=$.,join("",map"(?!\\$_)",1..$.++)."(.)")/ge;$_=<>=~$_
```
[Try it online!](https://tio.run/nexus/perl5#U1YsSC3KUdAtyPlfrK@nr5JRraJWa68UEwNhKVlpQBi2Kno6WfmZeRpKSjq5iQVKGvaKQDXxmko6hnp6Knra2pp6Shp6mkqa@ump1irxtjZ2tnUq8f//R0RGREZxJSXmAWExAA "Perl 5 – TIO Nexus")
XYXYZ is transformed into `((?!\1).)((?!\1)(?!\2).)\1\2((?!\1)(?!\2)(?!\3).)` (yup, some of the tests can't be true, but it's shorter that way), and the second input is then checked against that regex. (see the explanations of my older version to get more intuition of how it works)
---
My older version:  
*Thanks to Arnauld for pointing out a mistake I made in my first version.*  
113 bytes of code + `-pl` flags, and `-Mre=eval`.
```
s/./$h{$&}?"\\$h{$&}":($h{$&}=++$i,"(.)")/ge;$_.='(?{++$c;$\=1if!grep$v{$c}{${$_}}++,1..'.(keys%h).'})^';<>=~$_}{
```
[Try it online!](https://tio.run/nexus/perl5#JYndCoIwGEDvfQpdX21j9om3reVraEhi8vlDEuJIiLFe3QQ5N4dzDtFE8xiepzH4WApnCjkt9cj1ahNMoHdw8hkry93YRexilIIhZgIlk0lHGio0XGRuy42G0qRDG3UzTbA4aLwDB5X3SsUpIkfxoq899hK5lw@urzfz27Zb17zIi3vwrN8b9g8 "Perl 5 – TIO Nexus")
On the example XYXYZ: the first regex will convert the pattern to (.)(.)\1\2(.), and add at the end a test to check if `$1`, `$2` and `$3` are different: if so, `$\` is set to one. Then, the second input is testes against this regex, and `$\` is implicitely printed at the end.  
The regex generated for XYXYZ is `(.)(.)\1\2(.)(?{++$c;$\=1if!grep{$v{$c}{${$_}}++}1..3})^`.  
*(I'll to add a bit more details to the explanations when I have a moment)*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
=þ
ẆÇ€ċÇ}
```
Returns the number of times the pattern was found, non-zero being truthy and zero being falsy.
[Try it online!](https://tio.run/nexus/jelly#@297eB/Xw11th9sfNa050n24vfb/wx2bDi9XApK17v//F5cmJ6empiiA6eJihaTEnJz8/DwgnQeExVD6f0REZKQCEhEZERkFIQE "Jelly – TIO Nexus")
### How it works
```
ẆÇ€ċÇ}  Main link. Left argument: s (string). Right argument: p (pattern)
Ẇ       Window; generate all substrings of s.
 Ç€     Map the helper link over the substrings.
    Ç}  Apply the helper link to p.
   ċ    Count the number of times the right result appears in the left result.
=þ      Helper link. Argument: t (string)
=þ      Compare all characters of t for equality with all characters of t, yielding
        a square matrix of Booleans.
```
[Answer]
## JavaScript (ES6), 94 bytes
```
f=
(p,s)=>s.match(p.replace(/./g,c=>m[c]||(t=r,r=`(?!\\${++g})`+r,m[c]=`\\`+g,t),g=m=[],r=`(.)`))
```
```
<div oninput=o.textContent=!!f(p.value,s.value)><input id=p placeholder=Pattern><input id=s placeholder=String><span id=o>
```
Works by transforming the pattern into a regexp, e.g. for `XYXYZ` it generates `/(.)(?!\1)(.)\1\2(?!\2)(?!\1)(.)/`.
I notice an interesting distinction between PCRE and JavaScript regexp: in PCRE, `\<n>` fails (and therefore `(?!\<n>)` succeeds) before the capture group is defined, while JavaScript it succesfully matches the empty string (and therefore `(?!\<n>)` fails).
[Answer]
# [Python 2](https://docs.python.org/2/), 70 bytes
```
f=lambda p,s:s>''and(map(s.find,s[:len(p)])==map(p.find,p))|f(p,s[1:])
```
[Try it online!](https://tio.run/nexus/python2#dYtBCsIwEEX3nqJk0wwEwW0gniOxdDFtEiik08GpO@8eo66E@v/uPV7NruA6RezYiJVr3yNFvSJrOeeFopHBlkSaYQTn3py/nAGeWbdouNgRKt8X2ruslfchKKPkMc8pRQWnQyNyYCYsZdvowGDbDw4@3D4Ftct/paC@AA "Python 2 – TIO Nexus")
Checks if a string matches a pattern using the method in [this answer](https://codegolf.stackexchange.com/a/50612/20260). Uses a prefix of the search string whose length equals the pattern. Chops off the first character of the string string until a match is found, or `False` if it becomes empty
---
**73 bytes:**
```
f=lambda p,s:s>''and(map(s.find,s)==map(p.find,p))|f(p,s[1:])|f(p,s[:-1])
```
[Try it online](https://tio.run/nexus/python2#@59mm5OYm5SSqFCgU2xVbKeunpiXopGbWKBRrJeWmZeiU6xpawviFkC4BZqaNWkaQLXRhlaxMKaVrmGs5v@Cosy8EoU0DaWIiMhIJR2l4tLk5NTUFCVNLqwyxcVYZJISc3Ly8/OwyCQCAYpwZERkFFhHHhAW45ZS0vwPAA "Python 2 – TIO Nexus")
Checks if a string matches a pattern using the method in [this answer](https://codegolf.stackexchange.com/a/50612/20260). Recursively checks all substrings by branching into removing the first or last character until the string is empty.
[Answer]
# [Python 3](https://docs.python.org/3/), 100 bytes
```
l=len
f=lambda p,s:l(p)<=l(s)and(l({*zip(p,s)})==l({*p})==l({s for _,s in{*zip(p,s)}})or f(p,s[1:]))
```
[Try it online!](https://tio.run/nexus/python3#bY7LCsIwEEXXzVcMWWUkCC5ECOY/GkuR9AWFNA2durH022taFURlYLhz5i7O4rSr)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~19~~ 16 bytes
```
ÙœJv¹y…XYZ‡²åi1q
```
[Try it online!](https://tio.run/nexus/05ab1e#@3945tHJXmWHdlY@algWERn1qGHhoU2Hl2YaFv7/n5SYB4RcEZERkQA "05AB1E – TIO Nexus")
---
```
ÙœJ              # Get powerset of all unique characters in string.
   v             # Loop through each...
    ¹            # Push input word.
     y           # Push current set of letters in powerset.
      …XYZ‡      # Replace each of the 3 letters in the original word with XYZ.
           ²å    # Check if second input is in this string, push 1 if it is.
             i1q # If 1, push 1 and quit.
```
Will return 1 if true, null if not true.
---
This can be 14 bytes if returning the possible values of XYZ is allowed:
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
ÙœJv¹y…XYZ‡²å—
```
[Try it online 2!](https://tio.run/nexus/05ab1e#@3945tHJXmWHdlY@algWERn1qGHhoU2Hlz5qmPL/f1JiHhByRURGRAIA "05AB1E – TIO Nexus")
[Answer]
# Java 7, ~~177~~ ~~176~~ 173 bytes
```
Object c(String p,String s){int i=p.length();if(s.length()<i)return 0>1;for(;i-->0;)if(p.indexOf(p.charAt(i))!=s.indexOf(s.charAt(i)))return c(p,s.substring(1));return 1>0;}
```
**Explanation:**
```
Object c(String p, String s){                             // Method with two String parameters and Object return-type
  int i = p.length();                                     //  Index that starts at the length of the pattern
  if(s.length() < i)                                      //  If the length of the input is smaller than the length of the pattern
    return 0>1;//false                                    //   Simply return false
  for(;i-->0;)                                            //  Loop from 0 to length_of_pattern
    if(p.indexOf(p.charAt(i)) != s.indexOf(s.charAt(i)))  //   If the index of the characters of the pattern and input aren't matching
     return c(p, s.substring(1));                         //    Return the recursive-call of pattern and input minus the first character
                                                          //  End of loop (implicit / single-line body)
  return 1>0;//true                                       //  If every index of the characters are matching: return true
}                                                         // End of method
```
**Test code:**
[Try it here.](https://tio.run/nexus/java-openjdk#jY@/TsMwEIf3PMWRyZbSqJlNK/EAqEOXBMTgOG57yHUs3wWBqjx7cEuoYIHqlvvz6efPk3GaCB5PGQCxZjSwaV@tYTBiyxH9HkIxNyRP6BlwFUpn/Z4PQircCbpO9yij5SF6WK4rteujULhYrJdKJiyU6Dv7vjl35qDjAwuU8m5F1z392H8HGREKKmlo6eIgKinVfKpS8Jgl7zC0LnnP@m89dnDU6Gf/5xfQ8vw9gO0HsT2W/cBlSCd2XhiR13XT5AXkNBhjbZenF26liW6kW@1c3/sL/Rfe1M3TF@9T/Zv@G5/pMRun6RM)
```
class M{
  static Object c(String p,String s){int i=p.length();if(s.length()<i)return 0>1;for(;i-->0;)if(p.indexOf(p.charAt(i))!=s.indexOf(s.charAt(i)))return c(p,s.substring(1));return 1>0;}
  public static void main(String[] a){
    System.out.println(c("XXYY", "succeed"));
    System.out.println(c("XXYY", "success"));
    System.out.println(c("XXYY", "balloon"));
    System.out.println(c("XYXYZ", "bananas"));
    System.out.println(c("XYXYZ", "banana"));
  }
}
```
**Output:**
```
true
false
true
true
false
```
[Answer]
# PHP, 89 Bytes
A Gift from [@Christoph](https://codegolf.stackexchange.com/users/29637/christoph) and [@Titus](https://codegolf.stackexchange.com/users/55735/titus)
```
for(;$v=$argv[1][$i++];)$r.=$$v?"\\".$$v:"(.)".!$$v=++$j;echo preg_match("#$r#",$argv[2]);
```
# PHP, 105 Bytes
[A Gift from @Christoph](https://codegolf.stackexchange.com/users/29637/christoph)
```
foreach(str_split($argv[1])as$v)$r.=$x[$v]?"\\$x[$v]":"(.)".!$x[$v]=++$y;echo preg_match("#$r#",$argv[2]);
```
# PHP, 167 Bytes
```
[,$a,$b]=$argv;foreach($s=str_split($a)as$v)$r[]=$k++>strpos($a,$v)?"\\".(1+array_search($v,array_keys(array_count_values($s)))):"(.)";echo preg_match(_.join($r)._,$b);
```
[Answer]
## C#, 184 165 155 bytes
thanks aloisdg!
```
bool c(string p,string n){for(int l=p.Length,i=0,j;i<l;i++)for(j=i;j>=0;)if(p[i]==p[j]==(n[i]!=n[j--]))return l!=n.Length&&c(p,n.Substring(1));return 2>1;}
```
backtracking solution, as a bonus it works with a pattern with any characters!
```
    public static bool c(string p,string n)
    {
        for (int l = p.Length, i = 0, j; i < l; i++)
            for (j = i; j >= 0;)
                if (p[i]==p[j]==(n[i]!=n[j--]))
                    return l != n.Length && c(p,n.Substring(1));
        return 2>1;
    }
```
[Answer]
# Ruby, ~~63~~ 61 bytes
```
->a,b{a.chars.permutation.any?{|w|a.tr((w|[])*'','XYZW')[b]}}
```
Instead of searching for a regex pattern, just try substituting 'X','Y' and 'Z' in all possible ways, and find a literal match.
(Actually the same concept as carusocomputing's 05AB1E answer)
[Answer]
## JavaScript (ES6), ~~92~~ ~~89~~ ~~87~~ 86 bytes
Takes input `p` (pattern) and `s` (string) in currying syntax `(p)(s)`. Returns `0` / `1`.
```
p=>g=s=>s&&g(s.slice(1))|[...p].every((C,i,x)=>C==(x[c=s[i]]=x[c]||'XYZ'[c&&j++]),j=0)
```
### Formatted and commented
```
p =>                             // main function: takes pattern p as input, returns g
  g = s =>                       // g = recursive function: takes string s as input
    s &&                         // if s is not empty:
      g(s.slice(1))              //   do a recursive call, starting at the next character
    |                            // merge the result with this iteration
    [...p].every((C, i, x) =>    // for each character C at position i in p:
      C ==                       //   check whether C is matching the next expected
      (                          //   character, which is either:
        x[c = s[i]] = x[c] ||    //   - a substitution character already associated to s[i]
        'XYZ'[c && j++]          //   - the next substitution character ('X', 'Y' or 'Z')
      ),                         //   - undefined if c = s[i] doesn't exist or j > 2
      j = 0                      //   initialize j = pointer in 'XYZ'
    )                            //
```
### Test cases
```
let f =
p=>g=s=>s&&g(s.slice(1))|[...p].every((C,i,x)=>C==(x[c=s[i]]=x[c]||'XYZ'[c&&j++]),j=0)
console.log(f("XXYY")("succeed"))   // 1
console.log(f("XXYY")("success"))   // 0
console.log(f("XXYY")("balloon"))   // 1
console.log(f("XYXYZ")("bananas"))  // 1
console.log(f("XYXYZ")("banana"))   // 0
```
[Answer]
# Mathematica 18 characters (not counting string & pattern)
```
StringContainsQ[string,pattern]
```
Examples:
```
StringContainsQ["succeed", x_ ~~ x_ ~~ y_ ~~ y_]
```
`True`
```
StringContainsQ["bananas", x_ ~~ y_ ~~ x_ ~~ y_ ~~ z_]
```
`True`
]