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