title: Defining a RegEx Type in JSON Schema
body: <p>I am looking for an <em>elegant</em> way of checking that a value is a valid regular expression in a JSON schema. So far I have been content with requiring a <code>string</code> type:</p>
  
  <pre><code>{
      "pattern": { "type": "string" }
  }
  </code></pre>
  
  <p>I would like to make my check more strict and see that <code>pattern</code> is a valid regular expression:</p>
  
  <pre><code>{
      "definitions": {
          "regex": {
              ??? #not another regex -- that was already disproved
          }
      }
  
      "pattern": { "type": "regex" }
  }
  </code></pre>
  
  <p>By <em>valid</em> I mean checking that there are no syntax errors in the regular expression, such as open parentheses and so on.</p>
  
  <p>I thought for a while that one of the possible solutions was a regex that would match a regex, but I was shown this was already discussed for instance in <a href="https://stackoverflow.com/questions/362793/regexp-that-matches-valid-regexps">Regexp that matches valid regexps</a>, turning out that such an approach was impossible. What <strong>other</strong> ways are there?  I can think of a few directions this could lead, but could not find any information. Can I have the schema validator, for instance, somehow compile the regex? Do some validators support a <code>regex</code> primitive type unofficially? Is it in line to become a primitive type in JSON Schema v5, or some standard extension? Can I ``shell out'' of the schema and make the check? Or anything else?</p>