Solved

Regex Expression to get data between to tags

Posted on 2007-12-06
8
268 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
 
LVL 27

Expert Comment

by:ddrudik
ID: 20420464
Matches.Count
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now