Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Regex Expression to get data between to tags

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
EGormly
Asked:
EGormly
  • 5
  • 3
1 Solution
 
ddrudikCommented:
Provide your multiple instance case as an example.
0
 
ddrudikCommented:
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
 
EGormlyAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ddrudikCommented:
Matches.Count
0
 
ddrudikCommented:
Since Matches array would start at index 0, to loop through them:
For z = 0 to Matches.Count-1
0
 
EGormlyAuthor Commented:
Fastest response time ever, most complete answer I have ever received.
Thank you very much.
0
 
EGormlyAuthor Commented:
Thanks for going the extra mile and answering that for me.
0
 
ddrudikCommented:
Thanks for the question and the points, I am glad I could help.
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.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now