title: java regexp match morse code
body: <p>I'm trying to test if the Morse code is legal.</p>
  
  <pre><code>public static boolean isMorseCode( String code ){
  return code.trim().matches("[+.|+\s|+-]");      
  }
  </code></pre>
  
  <p>The Morse code line can begin with a <code>.</code> (known as Dit) and a <code>-</code> (known as Dah). It can have spaces in the line.
  1 space between two specific codes like <code>.- -.</code> in this case the sum of codes which are only separated by one white space is a word. But it can also have 3 white spaces and then a new word begins. I'm using trim to exclude the fact that there could be a white space at the beginning and end of the line.</p>
  
  <p>Here an example to make it more clear.</p>
  
  <p>We use "Hello World" for explanation. The white spaces are wiped out by posting them so take a look at <a href="http://www.rubular.com/r/r2iwqgUHCB" rel="nofollow">http://www.rubular.com/r/r2iwqgUHCB</a> there is also the regexp I used. In java it doesn't work.If someone could explain why it doesn't work or even show me how it does work I would be very thankful.</p>