Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regexp in java script to get text between tags

Posted on 1998-07-31
3
Medium Priority
?
365 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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

688 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