Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery match() variable interpolation - complex regexes
    primarykey
    data
    text
    <p>I've already looked at <a href="https://stackoverflow.com/questions/1695633?sort=newest#sort-top">this</a>, which was helpful to a point.</p> <p>Here's the problem. I have a list of users propagated into an element via user click; something like this:</p> <pre><code>&lt;div id="box"&gt; joe-user page-joe-user someone-else page-someone-else &lt;/div&gt; </code></pre> <p>On click, I want to make sure that the user has not already been clicked into the div. So, I'm doing something like: </p> <pre><code>if ( ! $('#box').html().match(rcpt) ) { update_div(); } else { alert(rcpt+' already exists.'); } </code></pre> <p>However, with existing lack of interpolation that javascript has for regular expressions, is causing my alert to trigger in the use-case where <code>page-joe-user</code> is selected and then the user selects <code>joe-user</code>, which are clearly not exactly the same.</p> <p>In Perl I would do something like:</p> <pre><code>if ( $rcpt =~ /^\Qrcpt\E/ ) { # code } </code></pre> <p>All I want to do is change my match() to be:</p> <pre><code>if ( ! $('#box').html().match(/^rcpt/) ) { # code } </code></pre> <p><code>if ( ! $('#box').html().match(rcpt) )</code> seemed a little promising but it, too, fails. Using <code>new RegExp()</code> also does not work using concatenation of complex RE syntax within the function IE <code>$('#box').html().match(new RegExp('^'+rcpt))</code>. I also tried <code>$('#box').html().match('/^'+rcpt'/')</code>. I can only imagine that I'm missing something. I'm pretty new to javascript.</p> <p>I don't seem to be able to find anything that really addresses such a use-case, here on this site.</p> <p>TIA</p>
    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.
 

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