This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes javascript string search funcion problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript string search funcion problem" Watch "javascript string search funcion problem" New topic
Author

javascript string search funcion problem

Ravinderjit Singh
Ranch Hand

Joined: Jan 13, 2010
Posts: 70
Hi,

Why search function is unable to find any match?
Here is my code



Result is -1

I know that putting the value inside () is causing this problem, but I am not getting why? Can anyone please shed some light on this?


Thanks.
Keith Wood
Author
Ranch Hand

Joined: Aug 28, 2012
Posts: 38

The parentheses are special characters in a regular expression, which is what your search string defines. To use these, and other special characters, as literal values you must escape them with a double backslash:



Author of the upcoming "Extending jQuery" book from Manning.
Ravinderjit Singh
Ranch Hand

Joined: Jan 13, 2010
Posts: 70
Thanks for your reply.
I resolved this by replacing special characters before search.
 
jQuery in Action, 2nd edition
 
subject: javascript string search funcion problem
 
Similar Threads
Why does "==" does not return false upon comparison of two String Literals??
response unable to receive the parameter sent
String formate
while-loop
Object expected line 37 char 1 code 0