title: ANTLR 4 - Grammar Rule for string to support whitespace and special char
body: <p>i am not experienced and still learning about grammar. i just need an example grammar that support for whitespace and special character like !,",#,$,^,&amp;. 
  Because with my current grammar and the rules inside i cant print out some string that support white space and special symbol. i know whitespace are tossed).</p>
  
  <p>For example if i give input : <strong>Hello      World!!!!!</strong>
  <br>the output is <strong>HelloWorld</strong> &lt;-- the whitespace &amp; char (!) tossed</p>
  
  <p>look at this image :
  <a href="https://i.stack.imgur.com/rDDmg.jpg" rel="nofollow noreferrer">problem</a></p>
  
  <p>why??</p>
  
  <p>here is my current grammar example.g4</p>
  
  <pre><code>    string
      : '"' (~'"'|'\"')* '"'
      ;
  
  Id
      : Letter(Letter|Digit)*
      ;
  
  Num
      : Digit
      ;
  
  fragment
      Digit
      : [0-9]+
      ;
  
  Letter
      : [a-zA-Z]
      ;
  
  
  LINE_COMMENT
      : '//' ~[\r\n]* -&gt; skip
      ;
  </code></pre>
  
  <p>i was read this link :
  <a href="https://stackoverflow.com/questions/23731646/antlr-parse-strings-keep-whitespaces-and-parse-normal-identifiers">ANTLR parse strings (keep whitespaces) and parse normal identifiers</a></p>
  
  <p>but i cant understand what happen. i need an advice. thanks.</p>