Regular Express Help Needed Please!

R

Raj.SB

I have a reg exp pattern as below works fine for the string : <param name="url" value="contents/cf_intro.htm" valuetype="ref">

mObjRegExp.pattern="<param.+?value=""([^""]+)""

But the same is not working for

<param name="url" valuetype="ref" value="../fmmain/fmindex.htm"

note that, i want to capture the url that comes after value=". if the value=" comes in the second place in the html tag it works. but if it comes in the 3rd position, then it doesn't work.
Can anyone help me finding the problem and make it work for both?thanks in advance.
 
C

Chris Hohmann

Raj.SB said:
I have a reg exp pattern as below works fine for the string : <param
name="url" value="contents/cf_intro.htm" valuetype="ref">.
mObjRegExp.pattern="<param.+?value=""([^""]+)"""

But the same is not working for

<param name="url" valuetype="ref" value="../fmmain/fmindex.htm">

note that, i want to capture the url that comes after value=". if the
value=" comes in the second place in the html tag it works. but if it
comes in the 3rd position, then it doesn't work.
Can anyone help me finding the problem and make it work for
both?thanks in advance.

What does "not working" mean? Please show more code. I tested the
regular expression you provided and it behaves as expected.
 
R

Raj.SB

Hi Thanks for the reply first

Not working means, the reg exp does not return the url in between the quotes after 'value=' from the following string
<param name="url" valuetype="ref" value="../fmmain/fmindex.htm"> . it works for this string
<param name="url" value="contents/cf_intro.htm" valuetype="ref">

the only difference between these two is the string i try to capture comes second in the working one, but in the not working string it comes as the third. am i explaining it clearly?
 
R

Raj.SB

<%
strLine = "<param name=""url"" valuetype=""ref"" value=""contents/cf_intro.htm"">" 'will return nothing
strLine = "<param name=""url"" value=""contents/cf_intro.htm"" valuetype=""ref"">" 'will return 'contents/cf_intro.htm'
Set mObjRegExp = New RegExp
mObjRegExp.IgnoreCase = True
mObjRegExp.MultiLine = True
mObjRegExp.Global = True

If InStr(lcase(strLine),"<param name=""url"" value=") Then
Response.write "StrLine(PARAM):"&strLine&"<BR>"

'mObjRegExp.pattern="<param.+?value=""([^""]+)"""

Set mObjMatches = mObjRegExp.Execute(strLine)

If mObjMatches.Count = 0 Then
Else
DescriptionParam = mObjMatches.item(0).Value
If Len(DescriptionParam) > 5 Then
DescriptionParam = Mid(DescriptionParam, InStr(1,DescriptionParam, "value=""", vbTextCompare) + 7)
DescriptionParam = Mid(DescriptionParam, 1, InStr(1, DescriptionParam, """", vbTextCompare)-1)
ParamFlag = 1
Else
ParamFlag = 0
End If
End If
Else 'Checking for Param applet links
End If 'Checking for Param applet links
Set mObjMatch = Nothing
Set mObjMatches = Nothing
Set mObjRegExp = Nothing
Response.write "<BR>test : " & DescriptionParam & "<BR>"
%>
 
C

Chris Hohmann

Raj.SB said:
<%
strLine = "<param name=""url"" valuetype=""ref""
value=""contents/cf_intro.htm"">" 'will return nothing
strLine = "<param name=""url"" value=""contents/cf_intro.htm""
valuetype=""ref"">" 'will return 'contents/cf_intro.htm'
Set mObjRegExp = New RegExp
mObjRegExp.IgnoreCase = True
mObjRegExp.MultiLine = True
mObjRegExp.Global = True

If InStr(lcase(strLine),"<param name=""url"" value=") Then
Response.write "StrLine(PARAM):"&strLine&"<BR>"

'mObjRegExp.pattern="<param.+?value=""([^""]+)"""

Set mObjMatches = mObjRegExp.Execute(strLine)

If mObjMatches.Count = 0 Then
Else
DescriptionParam = mObjMatches.item(0).Value
If Len(DescriptionParam) > 5 Then
DescriptionParam = Mid(DescriptionParam,
InStr(1,DescriptionParam, "value=""", vbTextCompare) + 7)
DescriptionParam = Mid(DescriptionParam, 1, InStr(1,
DescriptionParam, """", vbTextCompare)-1)
ParamFlag = 1
Else
ParamFlag = 0
End If
End If
Else 'Checking for Param applet links
End If 'Checking for Param applet links
Set mObjMatch = Nothing
Set mObjMatches = Nothing
Set mObjRegExp = Nothing
Response.write "<BR>test : " & DescriptionParam & "<BR>"
%>

Your outer IF statement checks for the following:

InStr(lcase(strLine),"<param name=""url"" value=")

This check fails for the first strLine listed.

HTH
-Chris Hohmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top