Solved

Regex Expression to get data between to tags

Posted on 2007-12-06
8
271 Views
Last Modified: 2012-05-05
I need a regex expresion to get the data between the following two tags:

<Product><11114-7></Product>

It has to loop as there may be up to 200 of them but as little as one.
I am using vbscript if that helps.
0
Comment
Question by:EGormly
  • 5
  • 3
8 Comments
 
LVL 27

Expert Comment

by:ddrudik
ID: 20420280
Provide your multiple instance case as an example.
0
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 20420327
If your data looks like:
<Product><11114-7></Product><Product><11114-8></Product><Product><11114-9></Product><Product><11114-10></Product>

With the <>:
<%
Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.MultiLine = True
teststring = "<Product><11114-7></Product><Product><11114-8></Product><Product><11114-9></Product><Product><11114-10></Product>"
regEx.Pattern = "<Product>([\S\s]*?)</Product>"
Set Matches = regEx.Execute(teststring)
%>

Without <>:
<%
Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.MultiLine = True
teststring = "<Product><11114-7></Product><Product><11114-8></Product><Product><11114-9></Product><Product><11114-10></Product>"
regEx.Pattern = "<Product><([\S\s]*?)></Product>"
Set Matches = regEx.Execute(teststring)
%>

If your example text differs from this format, provide your example text.
0
 

Author Comment

by:EGormly
ID: 20420436
wow that is phenomenal..
I must be a bit dense because try as I might, I just could not get that.
I spent a lot of time on regex tutorials and missed the <([\S\s]*?)> part, I couldn't seem to get it right.

One more quick question before I give you the points on this. (which I will regardless of if you answer)
How do I know how many results there are?

'Matches' is an array, that much I know, but how can I tell how many are in the array?


0
Technology Partners: 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!

 
LVL 27

Expert Comment

by:ddrudik
ID: 20420464
Matches.Count
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 20420475
Since Matches array would start at index 0, to loop through them:
For z = 0 to Matches.Count-1
0
 

Author Closing Comment

by:EGormly
ID: 31413171
Fastest response time ever, most complete answer I have ever received.
Thank you very much.
0
 

Author Comment

by:EGormly
ID: 20420498
Thanks for going the extra mile and answering that for me.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 20420513
Thanks for the question and the points, I am glad I could help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

685 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