Solved

How to find string using search in java script

Posted on 2014-07-21
3
137 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now