Solved

regexp in java script to get text between tags

Posted on 1998-07-31
3
359 Views
Last Modified: 2008-02-07
I've been using the folowing to strip out content in a document thats between certain tags and return the results in an array. There are multiple instances of this tag.
What I've been using looks like;

arrA = data.match(/<DATA>(.*)<\/DATA>/gi);
      
for (x=0; x<arrA.length; x++)
      Response.Write(arrA + "<BR>");

But all this does is return 1 result between the first data tag and the very last tag. Ignoring the tags in between. I should get a number of results.

I hope this makes sense


0
Comment
Question by:matthewallum
[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 1

Expert Comment

by:someu
ID: 1267511
How are you going to use the result??
It's for making a function or not.
someu@hotmail.com
0
 

Author Comment

by:matthewallum
ID: 1267512
I made a mistake in the line above, it should read;

Response.Write(arrA[x] + "<BR>");

sorry.
0
 
LVL 2

Accepted Solution

by:
bernfarr earned 100 total points
ID: 1267513
The way that the regular expression is written it would only return one value, I believe. Did you look at what was printed by your code?

I think you need to process the result with a further match operation where you specify the separators between your data tokens. In other words, what character, or characters separate your data values.  Assuming that each token was separated by a newline, you would need code something like: (This is untested)

allData = data.match(/<DATA>(.*)<\/DATA>/gi);

arrA = allData.match(/(\w+)$/gi);

for (x=0; x<arrA.length; x++)
  Response.Write(arrA + "<BR>");


Note that I always find regular expressions a pain to get right. Using Emacs, you can test them on a regular text file first.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Review of the nodejs code 1 36
How to get total count of passed in subject based on marks? 7 32
Coding for the first time 9 67
javascript and jquery question 4 22
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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

749 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