Solved

How to find string using search in java script

Posted on 2014-07-21
3
142 Views
Last Modified: 2014-07-23
Hi,
I have a string

var str = www.abc.com?<useridentifier>=[@ANaccount]

now in above string i want to search   ?<useridentifier>=[@ANaccount]

I have tried using search below
var str1 = str.search("\\?<useridentifier>=[@ANaccount]");

but this one is not working

can u please correct me above code
0
Comment
Question by:mannevenu26
3 Comments
 
LVL 7

Expert Comment

by:Raghu Mutalikdesai
ID: 40210708
Try this way:
var idx = str.indexOf("\\?<useridentifier>=[@ANaccount]");
var str1 = str.substring(idx, str.length - 1);

Open in new window

0
 

Author Comment

by:mannevenu26
ID: 40210727
var idx = str.indexOf("\\?<useridentifier>=[@ANaccount]"); not getting value getting idx as -1
0
 
LVL 11

Accepted Solution

by:
Radek Baranowski earned 500 total points
ID: 40210855
do it exactly as in

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28480214.html#a40208907

var str = "www.abc.com?<useridentifier>=[@ANaccount]";

var check=new RegExp ("[\?<useridentifier>=\[@ANaccount\]]");

//this will output position of "?" for testing purposes
if(check.test(str)==true) alert(str.search('\\?'));
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question