PDA

View Full Version : regExp


ShMiL
11-30-2002, 12:44 PM
what is the pattern for finding all substrings which are in this format:
<div>***</div>

*** = stands for all characters in every length. could be: "sdfag" could be "352lkjhsdff"...

Thanks!

brothercake
11-30-2002, 04:23 PM
<div>\([^<]+\)</div>

That will match at least one of any character except <

ShMiL
11-30-2002, 05:01 PM
this should work but it doesn't:

<%
Set rReg = New regexp
rReg.Pattern = "<div>\([^<]+\)</div>"
rReg.Global = False
rReg.IgnoreCase = True
Set objCols = rReg.Execute("<div>ddsag</div>dgsg<div>123</div>")

For Each objMatch In objCols
sInfo = sInfo & objMatch.Value
Next

Set objCols = Nothing
set rReg = nothing


response.write sInfo
%>

any idea why it returns nothing?

brothercake
11-30-2002, 08:06 PM
it might be a syntax thing. the backslash before the bracket is not always necessary, so maybe

<div>([^<]+)</div>

will do it

whammy
12-02-2002, 01:39 AM
<%
Dim strHTML
strHTML = "<div>asdf</div> *S&(DGF(S&DFH(SD&FH <div>rds</div> asdfasdf <div>qwer</div>"

'First, create a reg exp object
Dim objRegExp
Set objRegExp = New RegExp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<div>(.*?)</div>"

'Display all of the matches
Dim objMatch
For Each objMatch in objRegExp.Execute(strHTML)
Response.Write("<xmp>" & objMatch.Value & "</xmp><br />" & vbCrLf)
Next
%>


Output:

<div>asdf</div>


<div>rds</div>


<div>qwer</div>


I just googled it for the solution:

http://www.4guysfromrolla.com/webtech/043001-1.2.shtml

:D

ShMiL
12-02-2002, 11:38 AM
Last two replies were very helpful!
Thanks!

whammy
12-03-2002, 12:49 AM
:cool:

ShMiL
12-12-2002, 10:38 PM
Why won't this work:
Function findIt(str2check,str_start,str_end)
Dim objCols
Dim rReg
Dim objMatch
Dim sinfo

Set rReg = New regexp
rReg.Pattern = str_start & "([^<]+)" & str_end
rReg.Global = true
rReg.IgnoreCase = True
Set objCols = rReg.Execute(str2check)

For Each objMatch In objCols
sInfo = sInfo & objMatch.Value & ", "
Next

Set objCols = Nothing
Set objMatch = Nothing
set rReg = nothing
findIt = replace(replace(sInfo,str_start,""),str_end,"")
End Function
I use:
findit (str,"<td align=right width=120 nowrap>","</span></a></td>")
for this string:
<td align=right width=120 nowrap><a href="ts.cgi?tsscript=f/index&forum_id=1224&cat_id=306" class=w2><span dir=rtl>Shmil</span></a></td>
and I get NOTHING!

Any Idea?

ShMiL
12-14-2002, 10:12 AM
guys?
PLEEEEASE:confused:

whammy
12-14-2002, 11:06 AM
Probably because of this regular expression:

([^<]+)

You're looking for NOT a less than bracket; however there are many present in the string.

ShMiL
12-14-2002, 11:58 AM
So what could the problem be?
Can you think of a better reg. expression for this case?
Thanks.

whammy
12-14-2002, 11:58 AM
The one I posted should work with a bit of modification...