<%
Function Reggex(strString, strPattern, strReplace)
Dim RE: Set RE = New RegExp
With RE
.Pattern = strPattern
.Global = True
.IgnoreCase = True
Reggex = .Replace(strString, strReplace)
End With
End Function
Function ReplaceChar(strString)
fromDate="1-Jan-2000"
toDate=date
strString = Reggex(strString, "\[BusDate\]", ""&DateDiff("yyyy",fromDate,toDate)&"")
'This will give the output of 16 (being that it is 2016 now)
'However, what I need is to be able to type in the 2 dates.
strString = Reggex(strString, "\[theDate:([^\]]+)\|(.*?)\]", ""&DateDiff("yyyy","$1","$2")&"")
'However, the output in this example, will give me 1 (ONE)
ReplaceChar = strString
End Function
working = "[Busdate]"
testing = "[theDate:1950|2016]"
%>
Working: <%=ReplaceChar(working)%><br />
Non-working: <%=ReplaceChar(testing)%>
<%
Function Reggex(strString, strPattern) ', strReplace)
Dim RE: Set RE = New Regexp
With RE
.Pattern = strPattern
.Global = True
.IgnoreCase = True
If .Test(strString) Then
Set Reggex = .Execute(strString) ', strReplace)
Else
Reggex = strString
End If
End With
End Function
Function ReplaceChar(parmString, parmPattern)
Dim fromDate, toDate, oMatches
fromDate = "1-Jan-2000"
toDate = Date
'strString = Reggex(parmString, "\[BusDate\]", "" & DateDiff("yyyy", fromDate, toDate) & "")
'This will give the output of 16 (being that it is 2016 now)
'However, what I need is to be able to type in the 2 dates.
Set oMatches = Reggex(parmString, parmPattern) ', "" & DateDiff("yyyy", "$1", "$2") & "")
If oMatches.Count = 1 Then
Select Case oMatches(0).SubMatches.Count
Case 0
ReplaceChar = DateDiff("yyyy", fromDate, toDate)
Case 2
ReplaceChar = CLng(oMatches(0).SubMatches(1)) - CLng(oMatches(0).SubMatches(0))
End Select
Else
ReplaceChar = parmString
End If
'However, the output in this example, will give me 1 (ONE)
'ReplaceChar = strString
End Function
working = "[Busdate]"
testing = "[theDate:1950|2016]"
%>
Working: <%=ReplaceChar(working, "\[BusDate\]")%><br />
Non-working: <%=ReplaceChar(testing, "\[theDate:([^|]+)\|([^\]]+)\]")%>
IMPORTANT!!!
This ReplaceChar()
Is full with over 50 different tags.
So, I cannot change it, I need something, that I can simply just add to the exist function..
<%
Function Reggex(strString, strPattern, strReplace)
Dim RE: Set RE = New RegExp
With RE
.Pattern = strPattern
.Global = True
.IgnoreCase = True
Reggex = .Replace(strString, strReplace)
End With
End Function
Function ReplaceChar(strString)
fromDate="1-Jan-2000"
toDate=date
strString = Reggex(strString, "\[BusDate\]", ""&DateDiff("yyyy",fromDate,toDate)&"")
'This will give the output of 16 (being that it is 2016 now)
'However, what I need is to be able to type in the 2 dates.
strString = Reggex(strString, "\[theDate:([^\]]+)\|(.*?)\]", ""&DateDiff("yyyy","$1","$2")&"")
'However, the output in this example, will give me 1 (ONE)
ReplaceChar = strString
End Function
working = "[Busdate]"
testing = "[theDate:1950|2016]"
%>
Working: <%=ReplaceChar(working)%><br />
Non-working: <%=ReplaceChar(testing)%>
Function ReplaceTags(parmString, parmPattern, parmTransformType, Optional parmValue, Optional parmInterval = "yyyy")
Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
I tested it with this routine.Sub Q_28915256()
Dim strDoc 'As String
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
End Sub
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, Optional parmValue, Optional parmInterval = "yyyy")
Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Sub Q_28915256()
Dim strDoc 'As String
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
End Sub
%>
<%=strDoc%>
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Sub Q_28915256()
Dim strDoc 'As String
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
End Sub
%>
Is this the right way to use the function???
<%=ReplaceTags(strDoc)%>
Is this the right way to use the function???No. Look at the statements inside the Q_28915256 routine.
<%=ReplaceTags(strDoc)%>
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
ReplaceTags is a function that returns a string that has had replacements done. Since my sample string had several different kinds/flavors of tags, I had to invoke it several times, updating the strDoc variable with each result.
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Sub Q_28915256()
Dim strDoc 'As String
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date, "d")
End Sub
%>
Is this the right way to use the function???
<%
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
=ReplaceTags(strDoc)
%>
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Function Q_28915256()
Dim strDoc 'As String
strDoc = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc = strDoc & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
' strDoc = ReplaceTags(strDoc, "\[theWhole:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
Q_28915256 = strDoc
End Function
%>
Is this the right way to use the function???
<%=ReplaceTags(Q_28915256)%>
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Function Q_28915256(strDoc)
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")
strDoc = ReplaceTags(strDoc, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date, "d")
Q_28915256 = strDoc
End Function
strDoc1 = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:3-15-1991|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc1 = strDoc1 & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
%>
<%=Q_28915256(strDoc1)%>
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
End If
End Function
Function Reggex(strString, strPattern, strReplace)
Dim RE: Set RE = New RegExp
With RE
.Pattern = strPattern
.Global = True
.IgnoreCase = True
Reggex = .Replace(strString, strReplace)
End With
End Function
Function ReplaceChar(strString)
strString = ReplaceTags(strString, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")
strString = ReplaceTags(strString, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|birthDate\]", "AgeAtDate", Date, "yyyy")
strString = ReplaceTags(strString, "\[theWhole:([^|]*)\|theWhole\]", "DateDifference", Date, "d")
strString = ReplaceTags(strString, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date, "d")
strString = Reggex(strString, "\[b:(.*?)\]", "<strong title=""$1"">")
strString = Reggex(strString, "\[\/b\]", "</strong>")
ReplaceChar = strString
End Function
strDoc1 = "Now is the [BusDate] for all good men, aged [b:this is bold]this is bold[/b] [birthDate:10-19-1971|birthDate] to [birthDate:3-15-1991|birthDate] years old, to come to the aid of their country. " & vbCrLf
strDoc1 = strDoc1 & "This request is now [theWhole:11-25-2015|theWhole] days old as of [theDate:1950|2016]."
strDoc2 = "Now is the [BusDate] for all good men, aged [b:this is bold]this is bold[/b] [birthDate:10-19-1971|birthDate] to [birthDate:3-15-1991|birthDate] years old, to come to the aid of their country. " & vbCrLf
strDoc2 = strDoc2 & "This request is now days old as of [theDate:1950|2016]."
%>
<%'works'%>
<%=ReplaceChar(strDoc1)%><br />
<%'does not work (missing the [theWhole:11-25-2015|theWhole]'%>
<%=ReplaceChar(strDoc2)%>
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
Else
ReplaceTags = parmString
End If
End Function
<%
Function ReplaceTags(parmString, parmPattern, parmTransformType, parmValue, parmInterval)
'Static oRE 'As Object
Dim oMatches 'As Object
Dim oM 'As Object
Dim oSM 'As Object
Dim lngSM 'As Long
Dim lngAge 'As Long
Dim strTemp 'As String
If IsEmpty(oRE) Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
End If
oRE.Pattern = parmPattern
If oRE.test(parmString) Then
Set oMatches = oRE.Execute(parmString)
Select Case parmTransformType
Case "RepAllMatchesWithValue"
ReplaceTags = oRE.Replace(parmString, parmValue)
Case "RepMatchWithValue"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
strTemp = Left(strTemp, oM.firstindex) & parmValue & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "RepMatchWithSubmatchDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = oM.submatches(1) - oM.submatches(0)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "DateDifference"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue)
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
Case "AgeAtDate"
strTemp = parmString
For lngSM = oMatches.Count - 1 To 0 Step -1
Set oM = oMatches(lngSM)
lngAge = DateDiff(parmInterval, oM.submatches(0), parmValue) + ((Month(oM.submatches(0)) * 100 + Day(oM.submatches(0))) > (Month(parmValue) * 100 + Day(parmValue)))
strTemp = Left(strTemp, oM.firstindex) & lngAge & Mid(strTemp, oM.firstindex + oM.Length + 1)
Next
ReplaceTags = strTemp
End Select
Else
ReplaceTags = parmString
End If
End Function
Function Reggex(strString, strPattern, strReplace)
Dim RE: Set RE = New RegExp
With RE
.Pattern = strPattern
.Global = True
.IgnoreCase = True
Reggex = .Replace(strString, strReplace)
End With
End Function
Function ReplaceChar(strString)
strString = ReplaceTags(strString, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")
strString = ReplaceTags(strString, "\[birthDate:(\d{1,2}-\d{1,2}-\d{4})\|toDate\]", "AgeAtDate", Date, "yyyy")
strString = ReplaceTags(strString, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")
strString = ReplaceTags(strString, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date, "d")
strString = Reggex(strString, "\[b:(.*?)\]", "<strong title=""$1"">")
strString = Reggex(strString, "\[\/b\]", "</strong>")
ReplaceChar = strString
End Function
strDoc3 = "Now is the [BusDate] for all good men, aged [birthDate:10-19-1971|toDate] to [birthDate:1-1-2000|toDate] years old, to come to the aid of their country. " & vbCrLf
strDoc3 = strDoc3 & "This request is now [theWhole:11-25-2015|toDate] days old as of [theDate:1950|2016]."
%>
<%=ReplaceChar(strDoc3)%>
Not sure I understand the time tag question. This sentence doesn't make much sense to me. Can you rephrase it?
So, that when you type in the date: [birthDate:1971-2-19|toDate]
If you have an idea', would love to hear it.