Solved

search for sting with and store in variable

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
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…

759 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

25 Experts available now in Live!

Get 1:1 Help Now