title: Working with Strings in Java
body: <p>I need to implement the following:</p>
  
  <blockquote>
    <p>"$prefs" within the string "something something $prefs(something
    something)" should be returned. $prefs consists of letters form a-zAz
    and digits from 0-9. The "$" is always there.</p>
  </blockquote>
  
  <p>Finding the beginning of <code>$prefs</code> is no problem, but finding the end is trickier. As described above, <code>$prefs</code> could also be <code>$prefssdf</code>, followed be pretty much anything, like <code>(</code>, <code>,</code>, <code>&amp;&amp;</code>, and what not.</p>
  
  <p>Is there a way to do something like this:</p>
  
  <pre><code>while(string.elementAt(i) == [a-zA-Z0-9]){
      result += string.elementAt(i);
  }
  </code></pre>
  
  <p>An example:</p>
  
  <p>I have following string:</p>
  
  <pre><code>Select * from test where $prefs(select * from test2 where $prefs2);
  </code></pre>
  
  <p>I need to extract all occurrences of expressions with <code>$</code> prefixed, so in this case it is <code>$prefs</code> and <code>$prefs2</code>. How do I do that most efficiently?</p>