• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript string search funcion problem

 
Ravinderjit Singh
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


 
Ravinderjit Singh
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I resolved this by replacing special characters before search.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic