title: How to get the substring after cetain char, and if the char doesn't exist, return empty
body: <p>I have a string</p>
  <pre><code>VAR_A=&quot;127.0.0.1:12345&quot;
  </code></pre>
  <p>I want to split it into <code>HOSTNAME</code> and <code>PORT</code>, with the delimiter <code>:</code>.</p>
  <p>Per <a href="https://stackoverflow.com/a/15149278/10400141">this post</a>, I'm using this syntax to split the original <code>VAR_A</code> string:</p>
  <pre><code>HOSTNAME=${VAR_A%%:*}
  PORT=${VAR_A#*:}
  </code></pre>
  <p>And it works if <code>VAR_A</code> if of the form <code>xxxx:xxxx</code>.</p>
  <p>But I'd like to have the following result according to the value passed to <code>VAR_A</code>:</p>
  <ul>
  <li>If <code>VAR_A</code> doesn't contain the char <code>:</code>, e.g. <code>VAR_A=127.0.0.1</code>, then <code>HOSTNAME</code> is assigned with <code>127.0.0.1</code>, and assign empty string to <code>PORT</code></li>
  <li>If <code>VAR_A</code> contains the char <code>:</code> but nothing is after that <code>:</code>, e.g. <code>VAR_A=127.0.0.1:</code>, then same, <code>HOSTNAME</code> is assigned with <code>127.0.0.1</code>, and assign empty string to <code>PORT</code></li>
  <li>If <code>VAR_A</code> contains the char <code>:</code> but nothing before that <code>:</code>, e.g. <code>VAR_A=:12345</code>, then assign empty string to <code>HOSTNAME</code>, and <code>12345</code> to <code>PORT</code>.</li>
  </ul>
  <p>With current codes, if <code>VAR_A=127.0.0.1</code>, I got both <code>HOSTNAME=127.0.0.1</code> and <code>PORT=127.0.0.1</code>, which is not desired.</p>
  <p>If doable, I'd prefer a syntax similar to the one I provided -- the more succint/elegant the better.</p>