Solved

search for sting with and store in variable

Posted on 2012-03-19
3
159 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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

622 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