title: How to implement a strictly matching markdown with regex in java?
body: <p>I am trying to make a simple markdown parser in java, I only need one to make string bold and another one to change color to blue and also be able to combine both markdown.
  So for bold the words need to be places between double stars *, however, i don't want it to match if there are just 5 stars or more with nothing in between (many sites still match that and change 5 stars to a single bold one) so if the user was using the stars to draw a separator line or something they should just be displayed as is, but it should match if there is something with stars or other symbols like a math formula 4*5 (in other words, what is in between should not just be stars)</p>
  
  <p>Here is my code so far, it works to match bold, blue and both but still matches 5+ stars.</p>
  
  <pre><code>str = str.toString().replaceAll("\*\*(.+?)\*\*", "&lt;big&gt;$1&lt;/big&gt;");
  str = str.toString().replaceAll("\*b(.+?)\*\*", "&lt;font color='blue'&gt;$1&lt;/font&gt;");
  </code></pre>
  
  <p>i tried changing <code>(.+?)</code> to <code>(.+?&amp;&amp;[^\*])</code>, <code>(.*?[^\*].*?)</code>, <code>(.+?[^\*].*?)</code> and many other but they work for some and fail for other cases!</p>
  
  <p>Examples that should NOT match:</p>
  
  <pre><code>****
  *****    (5 and more stars)
  *Hi*
  ***Hi***
  **New\nLine**
  </code></pre>
  
  <p>Examples that should match either or both cases (Bold and Blue):</p>
  
  <pre><code>**Hi** : BOLD
  *bHi** : Blue
  ***bHi**** : BOLD and Blue
  *b**Hi**** : BOLD and Blue
  </code></pre>
  
  <p>also it should not match between multiple lines.</p>
  
  <p>Is what I am trying to do too complicated? can it be done with just regex?</p>
  
  <ul>
  <li>This is being done for Android in case it differs from normal java.</li>
  </ul>