Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

search for sting with and store in variable

Posted on 2012-03-19
3
Medium Priority
?
162 Views
Last Modified: 2012-03-19
Can you help me search of a string and store it in a variable?

 var strMatches = PageText.match('HQID:');

This will search the page for the word HQID and store it in "strMatches"

There are 10 random numbers after HQID that I need stored in the variable instead of HQID.  

Can you help with this?
0
Comment
Question by:ForLoop5
3 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 37737511
I assume you mean 10 random digits after HQID:
When it finds the string does it give you a position? You will need the starting position of the string, then use .substring to get part of it.
http://wwww.w3schools.com/jsref/jsref_substring.asp

Or if PageTextmatch takes regular expressions, that would be easier. You could tell it to find
HQID: and any 10 digits.
http://www.javascriptkit.com/javatutors/redev2.shtml

I'm not real good that them, but part would be something like
[0-9]{10}

You'd have to get the literal HQID: in front of that.  So something like
^[0-9]{10}

I don't remember how to do literal text
I'm not sure if you can just do
^HQID:[0-9]{10}
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 2000 total points
ID: 37737573
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo by Proculopsis</title>
 
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
 
 <script type='text/javascript'>//<![CDATA[
$(function(){
jQuery(document).ready(function() {

    var strMatches = $("body").text().match(/HQID:\d+/g);

    $(strMatches).each(function(index) {

        strMatches[index] = this.replace(/\D/g, "");

    });

    alert(strMatches);

});


});//]]>  

</script>


</head>
<body>
  Lorem ipsum dolor sit amet, consectetur HQID:123 adipisicing elit, sed do eiusmod tempor incididunt ut labore et HQID:321 dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor HQID:1 in reprehenderit in voluptate velit esse cillum dolore eu fugiat HQID:876 nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt HQID:666 mollit anim id est laborum.

</body>
</html>
0
 
LVL 1

Author Closing Comment

by:ForLoop5
ID: 37737702
Much appreciated.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

971 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