/    Sign up×
Community /Pin to ProfileBookmark

search method not working with variable reg exprs

Hello mates,
I am trying to use javascript search method to look for a string. Here is my code:

[CODE]for (;i<100;i++)
{
var search_txt=el.getValue();
var rg = new RegExp(search_txt,’i’);
var cname=record.data.company_name;
if (cname.search(rg)>=0)
return true;
}[/CODE]

But my above code is not working. Can someone kindly point out what I am doing wrong. It will be a great help. Thank you.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@dhaarbrinkMay 30.2008 — hmm .. what exactly do you use the for-loop for?

besides that: your code seems to be working.

i think el.getValue() or record.data.company_name result in empty or undefined values.

you should start debugging that!
Copy linkTweet thisAlerts:
@KorMay 30.2008 — Anyway, you have confounded the syntax: your substring should be used as a regular expression, not the string:
<i>
</i>[I]string[/I].search([I]rg[/I]);

<i>
</i>var search_txt=el.getValue();
var cname=record.data.company_name;
var rg = new RegExp(cname,'i');
if (search_txt.search(rg)&gt;=0){
return true;
}



On the other hand, why [B]search()[/B] and not [B]match()[/B]?
×

Success!

Help @tkm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...