Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21839

Question on regexp

$
0
0
I just started with regexp because I need it for a new application.

But I got stuck with html like replacements. I have something like this:

<SPAN class=day><A name=d1>monday</A></SPAN>On monday I eat apple...
<SPAN class=day><A name=d2>tuesday</A></SPAN>On tuesday I eat banana...
<SPAN class=day><A name=d3>wednesday</A></SPAN>On wednesday I eat peach...
<SPAN class=day><A name=d4>thursday</A></SPAN>On thursday I eat cherry...

Out of that I want to create:
<SPAN class=day><A name=d1>weekday</A></SPAN>On monday I eat apple...
<SPAN class=day><A name=d2>weekday</A></SPAN>On tuesday I eat banana...
<SPAN class=day><A name=d3>weekday</A></SPAN>On wednesday I eat peach...
<SPAN class=day><A name=d4>weekday</A></SPAN>On thursday I eat cherry...

But I get olny this with the following code:
<SPAN class=day><A name=d4>weekday</A></SPAN>On monday I eat apple...
<SPAN class=day><A name=d4>weekday</A></SPAN>On tuesday I eat banana...
<SPAN class=day><A name=d4>weekday</A></SPAN>On wednesday I eat peach...
<SPAN class=day><A name=d4>weekday</A></SPAN>On thursday I eat cherry...

The problem is, that everyday is day 4 :-(

This is my code:

Code:

Private Sub Command1_Click()
'regexp
    Dim RE As New RegExp
    Dim M As Match
    Dim T As String
    Dim intStart As Integer
    Dim intEnd As Integer
    Dim tmpStr1 As String
    Dim tmpStr2 As String
   
                T = Text1.Text
                RE.Pattern = "<A name=d.*?</A>"
                RE.Global = True
               
                For Each M In RE.Execute(T)
                    'ersetzt gefunden string
                    tmpStr1 = "<A name=d"
                    intEnd = InStr(Len(tmpStr1), M.Value, ">")
                    tmpStr2 = Mid(M.Value, Len(tmpStr1) + 1, intEnd - Len(tmpStr1) - 1) 'get the day-number /eg. 1,2,3,4,5,6,7
                    Text2.Text = RE.Replace(T, "<A name=d" & tmpStr2 & ">weekday</A>")
                Next
                               
               
End Sub



Any suggestion on what to change?

Viewing all articles
Browse latest Browse all 21839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>