title: Regex to grab "WORD" except after "#"
body: <p>I saw a SO question on here that uses Java <code>Matcher</code> and <code>Pattern</code> in an attempt to highlight text, similar to how <a href="https://regex101.com/" rel="nofollow noreferrer">Regex101</a> does it highlighting. He's specification was to highlight in a JTextArea for any literal string that is not preceded by a the literal character '#'. I was going to suggest creating your own <code>Matcher</code> and then the OP deleted his question :(</p>
  <p>That was the background, now here is my question. How can I use a regular expression to grab a literal string unless it's after (but not necessary adjacently) a specific string/character in a line?</p>
  <p>Example, if I wanted to select the string &quot;tester&quot; from the following</p>
  <blockquote>
  <p>tester, #tester</p>
  <p>test tester # test tester</p>
  <p>tester</p>
  </blockquote>
  <p>I would hope my regex would select</p>
  <blockquote>
  <p><strong>tester</strong>, #tester</p>
  <p>test <strong>tester</strong> # test tester</p>
  <p><strong>tester</strong></p>
  </blockquote>
  <p>but not the last &quot;tester&quot;.</p>
  <p>Using <a href="https://regex101.com/" rel="nofollow noreferrer">Regex101</a>, the closest I got was <code>/(?=tester)(?&lt;!#)tester/g</code> but this selects the last &quot;tester&quot; string since I cannot do a &quot;dynamic?&quot; (non-zero) length look back, as far as I can tell.</p>
  <p>EDIT:</p>
  <p>My question was not Java specific, otherwise I would of placed the Java tag. Unless <a href="https://regex101.com/" rel="nofollow noreferrer">Regex101</a> is wrong, I cannot use a <a href="http://www.regular-expressions.info/repeat.html" rel="nofollow noreferrer">Limiting Repetition</a> because &quot;Lookbehinds need to be zero-width, thus quantifiers are not allowed&quot;.</p>
  <p>I tested WiktorStribiżew regex in Java, and it works fine. Seeing it was a comment and not an answer, All I can do is +1 it, the Java String is <code>(?&lt;!#.{0,1000})\\btester\\b</code>. I tested it against the following Java String <code>tester, #tester\ntest tester # test testern\tester</code></p>
  <p>Side question, there is no fully defined way to handle regex across all languages? Or is is <a href="https://regex101.com/" rel="nofollow noreferrer">Regex101</a> just a poor testing tool (I was using their default, PHP engine)?</p>
  <p>I'll consider using <a href="http://regexstorm.net/tester" rel="nofollow noreferrer">RegexStorm</a> or <a href="http://regexhero.net/tester" rel="nofollow noreferrer">RegexHero</a> in the future.</p>