Help me find the right pattern!

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
Hey guys,

I got a problem using Regex with VBA.

From the following source code, I want the stuff in color to be submatched and the entire construct to be the match.

Code:
<td class="p">
	[COLOR="Red"]Highschool[/COLOR], [COLOR="#ffa500"]123456[/COLOR]  [COLOR="Red"]New York[/COLOR] </td>
</tr>
<tr background="../../images/transpbg.gif">
<td colspan="2" bgcolor="#FEA700"><img src="../../images/transparent.gif" width="1" height="2"></td>
</tr>
<tr valign = "middle"><td><a href="[COLOR="#ff0000"]/9720500[/COLOR]"><img src="../../icons/icon_homepage.gif" width="24" height="24" alt="Zur Homepage" title="Zur Homepage" border="0"></a>
	<a href="[COLOR="#ff0000"]einzelergebnis.html?Id=9720500&treffer=2&auswahl_1=0&auswahl_2=0&auswahl_3=0&suchtext=&kategorie=&region=de&trefferzahlauswahl=alle&trefferzahl=10412&list_anfang=0&sort=[/COLOR]"><img src="../../icons/icon_info.gif" width="24" height="24" alt="Information" title="Information" border="0"></a>
</td>

Now my pattern looks like this:

Code:
.Pattern = "<td class=.*?>[COLOR="#ff0000"](.*?)[/COLOR], [COLOR="DarkOrange"](\d+)[/COLOR] [COLOR="#ff0000"](.*?)[/COLOR]</td>.*?<tr valign.*?><td><a href=.*?[COLOR="#ff0000"](\\\d+)[/COLOR]" _
    & "<img src=.*?<a href=[COLOR="Red"](.*?)[/COLOR]<img src=.*?</td>"

What is incorrect?

I know this is a bit of a mess, but maybe there is a tiny mistake and I dont see it.

Help would be greatly appreciated.
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Code:
With CreateObject("VBScript.RegExp")
    .Global = True
    .ignorecase = True
    .Pattern = "<td class=.*?>[COLOR="#ff0000"](.*?)[/COLOR], [COLOR="DarkOrange"](\d+)[/COLOR] [COLOR="#ff0000"](.*?)[/COLOR]</td>.*?<tr valign.*?><td><a href=.*?[COLOR="#ff0000"](\\\d+)[/COLOR]" _
    & "<img src=.*?<a href=[COLOR="Red"](.*?)[/COLOR]<img src=.*?</td>"
    If .test(jQText) Then
        Set jMatch = .Execute(jQText)
        jCount = 0
        Do Until jCount = jMatch.Count
            jS.Cells(jCount + 1, 1) = Trim(jMatch(jCount).submatches(1))
            jS.Cells(jCount + 1, 2) = Trim(jMatch(jCount).submatches(2))
            jS.Cells(jCount + 1, 3) = Trim(jMatch(jCount).submatches(3))
            jS.Cells(jCount + 1, 4) = Trim(jMatch(jCount).submatches(4))
            jS.Cells(jCount + 1, 5) = Trim(jMatch(jCount).submatches(5))
            jCount = jCount + 1
        Loop
    End If
End With

What is wrong with that, why do I not get the right matches. It is all over the place for me.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top