Solved

Regex Expression to get data between to tags

Posted on 2007-12-06
8
269 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
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…

919 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

19 Experts available now in Live!

Get 1:1 Help Now