Java expression: Not allow single quote in middle or Allow single quote with double back slash
<p><strong>The format I want to validate</strong></p>

<ol>
<li>Start with single quote (after left trim)</li>
<li>End with single quote (after right trim)</li>
<li>In the middle: No single quote allowed OR allow it but it must be escaped using double back slash</li>
</ol>

<p><strong>Samples</strong></p>

<pre><code>'abc' --&gt; valid
'abc\\'def' --&gt; valid
'abc'def' --&gt; invalid
</code></pre>

<p><strong>What I tried</strong></p>

<pre><code>public static void main(String[] args) {

    final Pattern pat = Pattern.compile("\\s*\\'[^']+\\'\\s*", Pattern.CASE_INSENSITIVE);

    System.out.println(pat.matcher("'abc'").matches());  // Out: true
    System.out.println(pat.matcher("'abc\\'def'").matches()); //Out: false, expected true
    System.out.println(pat.matcher("'abc'def'").matches()); // out false
}
</code></pre>

<p><strong>I am having issue with this rule:</strong></p>

<pre><code>allow a single quote in middle but it must be escaped by \\
</code></pre>

<p>Any helps? Thanks!</p>