title: Regular expression in R behaves differently than in other languages
body: <p>The regular expression pattern <code>^[A-Z]{2,4}$</code> specifies that the string to be matched should start with an uppercase letter and end with an uppercase letter. It also requires that there be exactly two, three, or four letters present. Anything else will not be considered valid:</p>
  
  <pre><code>filter_symbols &lt;- function(symbols) {
    valid &lt;- regexpr("^[A-Z]{2,4}$", symbols)
    return(sort(symbols[valid == 1]))
    #valid
  }
  filter_symbols(c("MOT", "CVX", "123", "GOG2", "XLE", "AAPL", "AAPLS", "A"))
  </code></pre>
  
  <p>...and it works like a charm:</p>
  
  <pre><code>[1] "AAPL" "CVX"  "MOT"  "XLE" 
  </code></pre>
  
  <p>Now when you test the same code here (and there are many similar online regex tester out there):</p>
  
  <pre><code>^[A-Z]{2,4}$
  </code></pre>
  
  <p><img src="https://www.debuggex.com/i/_uQIi2Q-s6HzV4-L.png" alt="Regular expression visualization"></p>
  
  <p><a href="https://www.debuggex.com/r/_uQIi2Q-s6HzV4-L" rel="nofollow">Debuggex Demo</a></p>
  
  <p>...you <strong>don't get any match</strong> (neither when you start the words in new lines each) - why is it behaving differently in both cases?</p>