By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,445 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

regex submatch (copied to vb for more support)

P: 8
I just need to capture and display text portion of HTML page.

<p class="header" style="margin-top:35px; margin-bottom:0px;">
text I want to caputre</p>

Obviously my site runs vbscript version 5 and does not support submatches nor expression that I wanted to use. (no. I can't upgrade)

Anyway.
How would I just capture text portion of this tag and display?
I was thinking something like this but I do not want <TAG> to appear

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(URLString), ForReading)
strContent = objTextFile.ReadAll
objTextFile.Close
set objTextFile = nothing
set objFSO = nothing

Set objRegExp = New RegExp
with objRegExp
.Pattern = "<p[^>]*header.*>([^<]+|.*)?<\/p>"
.IgnoreCase = True
end with
If colMatches.Count > 0 Then
Response.Write "Test result: " & colMatches.item(0).value <<<<<<<<<<<<<<<<<<<<< how can I just get value only within ()?
Response.Write colMatches.Count & " matches!"

For Each strMatch in colMatches
Response.Write strMatch.Firstindex & strMatch.Value
Next
Else
Response.Write "string not found"
End if
Set objRegExp = nothing

better pattern would be appreciated but mostly I would like to know how I can only display text portion within the tag.

Thank your help!
Apr 16 '07 #1
Share this Question
Share on Google+
5 Replies


iam_clint
Expert 100+
P: 1,208
i would do something silly like this
Expand|Select|Wrap|Line Numbers
  1. dim example
  2. example = "<p class=""header"" style=""margin-top:35px; margin-bottom:0px;"">text I want to caputre</p>"
  3. example = split(example, "<")(1)
  4. example=split(example, ">")(1) 
  5. response.write example
  6.  
- Edit: but as I can see your looking for something more complex.
Apr 16 '07 #2

iam_clint
Expert 100+
P: 1,208
i'm not great at regular expressions but there is a program i know of to help build them its called the regulator, its free and heres a link.

http://sourceforge.net/projects/regulator/
Apr 16 '07 #3

P: 8
i would do something silly like this
Expand|Select|Wrap|Line Numbers
  1. dim example
  2. example = "<p class=""header"" style=""margin-top:35px; margin-bottom:0px;"">text I want to caputre</p>"
  3. example = split(example, "<")(1)
  4. example=split(example, ">")(1) 
  5. response.write example
  6.  
- Edit: but as I can see your looking for something more complex.
yes, I would not use regex if text in var example is consistent. I have a few hundred pages constructed this way.
All contains form of this tag.
I do need to get the text out of each pages.
Apr 16 '07 #4

P: 8
i'm not great at regular expressions but there is a program i know of to help build them its called the regulator, its free and heres a link.

http://sourceforge.net/projects/regulator/
Problem here is that I can do this easy in vb 5.5 or later using submatch.. and use it as follows, but again this problem comes with vb 5 regex engine.
.
.

.Pattern = "<p[\s]+[^>]*?class[\s]?=[\s""\']+blackheader[\s""\']+.*?>([^<]+|.*?)?<\/p>"
.
.
.
If strMatch.SubMatches.Count >=1 Then
Response.Write strMatch.SubMatches(0)
End If
.
.
.
Apr 16 '07 #5

iam_clint
Expert 100+
P: 1,208
darn man you have me stumped maybe someone more familiar with regular expressions and vb5 will figure it out i'll have some people come look at the post.


also i'll copy this into visual basic help, asp and vb are so close maybe they will have an answer for you.
Apr 16 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.