Solved

search for sting with and store in variable

Posted on 2012-03-19
3
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Industry Leaders: 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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

734 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