Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Javascript supports <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-negated-look-ahead" rel="noreferrer">negative lookahead</a>, one safe way to do it is:</p> <p>Let say you want to do a lookbehind like this</p> <pre><code>(?&lt;!([abcdefg]))m </code></pre> <ol> <li>Reverse the string to match</li> <li><p>Apply your pattern "reversed" using a lookahead (be careful of the reversed matching expression inside the lookahead, in this case, it stays the same)</p> <pre><code>m(?!([abcdefg])) </code></pre></li> <li><p>reverse all the matched tokens</p></li> </ol> <p><strong>Examples:</strong> </p> <p>I define the following functions:</p> <pre><code>const reverse = s =&gt; s.split('').reverse().join(''); const test = (stringToTests, reversedRegexp) =&gt; stringToTests .map(reverse) .forEach((s,i) =&gt; { const match = reversedRegexp.test(s); console.log( stringToTests[i], match, 'token:', match ? reverse(reversedRegexp.exec(s)[0]) : 'Ø' ); }); </code></pre> <p><strong>Example 1:</strong></p> <p>Following @andrew-ensley's question:</p> <pre><code>test(['jim', 'm', 'jam'], /m(?!([abcdefg]))/) </code></pre> <p>Outputs:</p> <pre><code>jim true token: m m true token: m jam false token: Ø </code></pre> <p><strong>Example 2:</strong></p> <p>Following @neaumusic comment (match <code>max-height</code> but not <code>line-height</code>, the token being <code>height</code>):</p> <pre><code>test(['max-height', 'line-height'], /thgieh(?!(-enil))/) </code></pre> <p>Outputs:</p> <pre><code>max-height true token: height line-height false token: Ø </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload