473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Match Function with character +

Hi,

I am using match function of string to find if a character is there in a
string. The function Match is working fine with all the other characters
except when the searching character is "+".

Here is the piece of code i am using

var line1 = "Hell+O";

if(line1.match("+"))
{
alert("The character is found");
}
In the above code it should alert the statement "The character is found".

Please help me out.
Regards,
Venkat

Jul 20 '05 #1
1 3956
"Venkat" <ve*******@yahoo.com> wrote in message
news:1065738057.816453@sj-nntpcache-5...
I am using match function of string to find if a character is
there in a string. The function Match is working fine with all
the other characters except when the searching character is "+".

Here is the piece of code i am using

var line1 = "Hell+O";

if(line1.match("+"))
{
alert("The character is found");
}

In the above code it should alert the statement
"The character is found".


The String.prototype.match method is expecting a regular expression as
its argument. You are passing it a string argument and the ECMA Script
specification does not define behaviour under these circumstances.
However, it is likely (especially if this is working under other
circumstances) that the string is internally being converted into a
regular expression with - new RegExp("+"); - but an unescaped +
character is meaningful to regular expressions and this will not result
in a regular expression that will test for the presence of the +
character in the string.

You might have better luck specifically defining the regular expression
you are passing to the match method as - line1.match( /\+/ ) - , but
regular expressions are relatively heavyweight if the desired task is
just to determine whether a string contains at least one instance of a
single character. String.prototype.indexOf would probably be more
efficient, using a test such as:-

if( line1.indexOf("+") >= 0 ){
alert("")
}

Richard.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ron Adam | last post by:
Is it possible to match a string to regular expression pattern instead of the other way around? For example, instead of finding a match within a string, I want to find out, (pass or fail), if...
3
by: bdwise | last post by:
I have this in my body tag: something();something(); document.thisForm.textBox1.focus();something(); And I want to find a part between the semicolons that ends in focus() and remove the...
2
by: Sriram | last post by:
Hi, I am having trouble matching a regex that combines a negated character class and an anchor ($). Basically, I want to match all strings that don't end in a digit. So I tried: ...
19
by: Tom Deco | last post by:
Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. ...
2
by: brad | last post by:
Hello all, I'm new to javascript--not too new to a few other programming languages--and I need your help deciphering the Regexp in the following string. Regular expresions are hard enough in...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
2
by: Jon Slaughter | last post by:
Can I use any reg exp(mainly for mod rewrite) where I can match any character but a fixed list? I need to match a string that does not contain any /'s but I don't want to have to use a character...
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
6
by: Andrus | last post by:
I need to implement vfp function which uses * and ? wildcards: static bool Like( cExpression1, cExpression2) cExpression1 Specifies the character expression that Like( ) compares with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.