Home > Archive > Visual Basic > March 2004 > Need help with Regular Expression
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need help with Regular Expression
|
|
| Scott Emick 2004-03-30, 5:30 pm |
| I have the following program (just to test the regex). I want it to
return the first subfolder under the root. In the program below, I
should get:
GBA
interdealers
interdealers
If there is not a folder, I want no matches to be returned.
What I am getting however, is INT1 returned in the last example.
Thanks,
Scott Emick
dim regex
set regex = new regexp
regex.pattern=".*\/\/www.bla.com.*\/(.*){1}\/.*"
regex.IgnoreCase=true
regex.global=false
strng="http://www.bla.com/GBA/index.cfm?id=154"
Set Matches = regEx.Execute(strng) ' Execute search.
cycleMatches matches
strng="http://www.bla.com/interdealers/index.cfm?id=154"
Set Matches = regEx.Execute(strng) ' Execute search.
cycleMatches matches
strng="http://www.bla.com/interdealers/INT1/index.cfm?id=154"
Set Matches = regEx.Execute(strng) ' Execute search.
cycleMatches matches
Private Sub subMatches(match)
if match.submatches.count=0 then
wscript.echo "no sub matches"
else
for intCount=0 to (match.submatches.count-1)
WScript.echo strng & "s '" & match.submatches(intCount) & "'"
next
end if
end sub
Private Sub cycleMatches(matches)
if matches.count=0 then
wscript.echo "no matches"
else
submatches matches(0)
end if
End Sub
| |
| Pásztor, Zoltán 2004-03-31, 10:30 am |
| Try this:
regex.pattern = "//www\.bla\.com[^/]*/([^/]*)/"
--
PZ
Scott Emick wrote:
> I have the following program (just to test the regex). I want it to
> return the first subfolder under the root. In the program below, I
> should get:
>
> GBA
> interdealers
> interdealers
>
> If there is not a folder, I want no matches to be returned.
>
> What I am getting however, is INT1 returned in the last example.
>
> Thanks,
> Scott Emick
>
> dim regex
> set regex = new regexp
>
> regex.pattern=".*\/\/www.bla.com.*\/(.*){1}\/.*"
> regex.IgnoreCase=true
> regex.global=false
> strng="http://www.bla.com/GBA/index.cfm?id=154"
> Set Matches = regEx.Execute(strng) ' Execute search.
> cycleMatches matches
>
> strng="http://www.bla.com/interdealers/index.cfm?id=154"
> Set Matches = regEx.Execute(strng) ' Execute search.
> cycleMatches matches
>
> strng="http://www.bla.com/interdealers/INT1/index.cfm?id=154"
> Set Matches = regEx.Execute(strng) ' Execute search.
> cycleMatches matches
>
> Private Sub subMatches(match)
> if match.submatches.count=0 then
> wscript.echo "no sub matches"
> else
> for intCount=0 to (match.submatches.count-1)
> WScript.echo strng & "s '" & match.submatches(intCount) & "'"
> next
> end if
> end sub
> Private Sub cycleMatches(matches)
> if matches.count=0 then
> wscript.echo "no matches"
> else
> submatches matches(0)
> end if
> End Sub
|
|
|
|
|