Java regex - matcher with multiple string clarifications
<p>Input</p>

<pre><code>45697B2
</code></pre>

<p>regex pattern:</p>

<pre><code>static Pattern kindCodePattern = Pattern.compile("([a-zA-z])", Pattern.CASE_INSENSITIVE);
</code></pre>

<p>What i do</p>

<p>from the input taken last two char and match single char range a-z, if find remove the last two char else assign an empty </p>

<pre><code>kindCode = input.substring(Math.max(input.length() - 2, 0));
        matcher = kindCodePattern.matcher(kindCode);
        Boolean isAvailableKindCode = matcher.find();
        if (isAvailableKindCode) {
            input = input.substring(0, input.length() - 2);
        } else {
            kindCode = "";
        }
</code></pre>

<p>but some case i want to check the last char only, like if my input was <code>45697B</code> then</p>

<pre><code>kindCode = input.substring(Math.max(input.length() - 1, 0));
</code></pre>

<p>doubt:</p>

<p>how can i match both cases in an single matches? is it possible?</p>

<p>or any changes in my pattern?</p>