title: Regular expression matching my condition
body: <p>I have added this regular expression in my code</p>
  
  <pre><code>\s\$\w+\.*\w+%*\s
  </code></pre>
  
  <p>I thought it would match and tokenize the below scenario in my input string:</p>
  
  <ol>
  <li>$var1 $var2 </li>
  <li>$var1
  <p> $var2</li>
  </ol>
  
  <p>I observe that case 2 it splits my input as 2 matches, var1, var2. But in case 1 $var1 is considered a match and $var2 is ignored . Would case it not fall into my RE as-"any word that starts with space followed with dollar ends with space" and split my input as 2 matches? If not could anybody please explain the way to correct it as well as tell me why the above RE fails.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>List&lt;String&gt; values = new ArrayList&lt;String&gt;();
      str = " " + str;
      String pattern = (StringConstants.PATTERN_DOLLER_VALUE);
      Pattern patternComplie = Pattern.compile(pattern);
      if (!StringUtils.isBlank(configTemplateString)) {
          Matcher matcherConfigTemplateString = patternComplie
                  .matcher(configTemplateString);
          while (matcherConfigTemplateString.find()) {
              String placeHolder = matcherConfigTemplateString.group();
              System.out.println("placeholder :" + placeHolder);
              values.add(matcherConfigTemplateString.group().trim());
  </code></pre>
  
  <p>The "PATTERN_DOLLER_VALUE" has the pattern that I mentioned above. Values is a arraylist which hols tokens.</p>