This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 78
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: 78
Thanks for your reply.
I resolved this by replacing special characters before search.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript string search funcion problem