title: Regex order when matching single square bracket
body: <p>Hello to all of you,</p>
  
  <p>I have a question regarding a specific regex in Elisp and specifically in Elisp. I'm trying to match a single square bracket and ielm has this:</p>
  
  <pre><code>  (string-match "[\]\[]" "[")  ; ===&gt; 0
    (string-match "[\[\]]" "[")  ; ===&gt; nil
  
    (string-match "[\]\[]" "]")  ; ===&gt; 0
    (string-match "[\[\]]" "]")  ; ===&gt; nil
  
    (string-match "[\[\]]" "[]") ; ===&gt; 0
    (string-match "[\]\[]" "[]") ; ===&gt; 0
    (string-match "[\]\[]" "][") ; ===&gt; 0
    (string-match "[\]\[]" "][") ; ===&gt; 0
  </code></pre>
  
  <p>Where as with JS, these all return true:</p>
  
  <pre><code>'['.match(/[\[\]]/) // ===&gt;['[']
  '['.match(/[\]\[]/) // ===&gt;['[']
  
  
  ']'.match(/[\[\]]/) // ===&gt;[']']
  ']'.match(/[\]\[]/) // ===&gt;[']']
  
  '[]'.match(/[\[\]]/) // ===&gt;['[']
  '[]'.match(/[\]\[]/) // ===&gt;['[']
  ']['.match(/[\[\]]/) // ===&gt;[']']
  ']['.match(/[\]\[]/) // ===&gt;[']']
  </code></pre>
  
  <p>Here's a regex101: <a href="https://regex101.com/r/e8sLXr/1" rel="nofollow noreferrer">https://regex101.com/r/e8sLXr/1</a></p>
  
  <p>I don't understand why the order of my square brackets in Elisp matters. I've tried using double backslashes but it doesn't help. Actually, it gives me more nils on these regexes whereas I thought the proper way to escape a backslack in a string for the regex to process was to double it: <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Example.html#Regexp-Example" rel="nofollow noreferrer">https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Example.html#Regexp-Example</a></p>
  
  <p>Does anyone know what I'm missing a could help me ?</p>
  
  <p>Cheers,</p>
  
  <p>Thomas</p>
  
  <p>EDIT: grammar</p>