Solved

How to find string using search in java script

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now