Avatar of Wayne Barron
Wayne Barron
Flag for United States of America asked on

Get the difference between 2 dates in RegEx (ASP Classic)

Hello All;

I need to get the different between 2 dates inside of a RegEx script.
The following script demonstrates one that works, and the other that does not work.

<%
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)%>

Open in new window


I know there has to be a way to do this.
Any idea's?
ASPVisual Basic ClassicVB Script

Avatar of undefined
Last Comment
aikimark

8/22/2022 - Mon
aikimark

I'm not sure what you are trying to accomplish with your example code.  Could you just give some examples of strings and the resulting date differences you need to calculate?
Wayne Barron

ASKER
In this line here
[theDate:1950|2016]

basically, I want to be able to place 2 years, no matter what they are together.
And have it calculate the output on the live site.

So, if I do an article where the person was born 1945, and they died 1998, then It will calculate there age (53)

Something like that.
aikimark

@Wayne

But, 'age' is a step function and not merely the difference in years.  For instance, The difference between this year and my birth year is 61.  However, I won't actually turn 61 until the fourth quarter.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
aikimark

Try this:
<%
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:([^|]+)\|([^\]]+)\]")%>

Open in new window

Wayne Barron

ASKER
Nice, but it changes up my code way to much, which will break all the tags on over 100 pages and growing.

Writing the way you have it here.
<%=ReplaceChar(testing, "\[theDate:([^|]+)\|([^\]]+)\]")%>
I cannot do.
It has to be the way that I had it in the demo, in order for it to work in my project.
<%=ReplaceChar(working)%>

I love the script, it is nice.
But, it will not work within my existing site.
aikimark

@Wayne

Since you have only shown a snippet of the code and two examples, it wasn't possible to answer your question without the expected side effects.  How about describing the problem without code and give at least as many examples as your data configurations.

For example:

I need a general purpose routine that will replace tags in my document with different date/year differences, depending on the nature of the tag.  There are four possible configurations of tag text as follows:
*
*
*
*
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
In the example that I provided, it shows what I need to do.
There is not very much more that I can say really.

Using the same code that I provided.
I need to be able to take 2 dates, that I insert into the tag.
And have the output to be the resulting number.

This could be a comparison between a
Birth year and Death year
Start year and End year
Start date and today's date (in ASP will be  toDate=date(), there for it will grab the date itself)

See, this is needed, so that I do not have to go in and update every page on the site, with a new date.
There is over 100 articles on the site so far.
By the summer, that could be up to OR over 1,000 articles and counting.

If I have to edit dates across, just 1/4 of them articles, it would be a complete nightmare.

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..

I hope that this helps.
aikimark

Please post your actual ReplaceChar code
Wayne Barron

ASKER
aikimark.
That replace code that I posted at the top here.
This is my actual code.
It is just 2 parts inside, instead of all of it.
The example that I posted, it what I am using.
There is nothing different from what I posted..

This is it, this is the code that I am using.... just with 2 tags.

<%
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)%>

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
aikimark

There needs to be something in one or more of the routines, that takes the presence of submatches into consideration.  Your replacement value is dependent on this.
Either that or two separate routines for simple replace and submatch-dependent replacing.
Wayne Barron

ASKER
aikimark.
You lost me on what you just wrote.
You seem to be very intelligent in your work, and I can tell it by the articles that you have written.
However, with what you just wrote, it is completely over my head, as bad as it is to say that, it is.

You explain to me, exactly what you need from me, and I will try to provide that to you.

I will say this much (Added to my previous posts provided code)
This is going on, for what you wrote in this post above. http:a41415792

lets say that there is a YEAR only date, then it would need to be.
[theDate:1950|2016] output to: 66
[birthDate:2-19-1971|toDate] output to: 44 (not quite 45 yet)
[theWhole:11-25-2015|toDate] output to: 54 days ago

Something like that.
If there is anything else that you need, please let me know.
If you need to use it in a different function.
Then just try to make it work along side the function that I have provided.

I really do not know what else to add.
Please let me know if you need anything else from me.
aikimark

Thank you for those examples.  In addition to "[BusDate]", you have defined four different scenarios.  We are now one step closer to defining your requirements.

1. How will the code know whether the date difference is to be expressed in years or days or age-at-current-date?
2. Will there be a single instance of each tag in your document?  In other words, might there be both
[birthDate:3-15-1991|toDate] and [birthDate:2-19-1971|toDate] in the same document?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
#1: The only way I know to answer this question, is by stating, that with the tag code reference.
       Each tag will have its own code to output the proper information that is given to the tag.

#2:  There could be multiple instances of all tags in a single document.
aikimark

Is the birthDate tag the determination of whether the result is in years or age at date?
Is the theWhole tag the determination of whether the result is in years or days?

Do you have control over these tags or are they already in their final state in the document?
Wayne Barron

ASKER
Yes to the first 2 questions.
And Yes to the 3rd question, however, as stated above.
I cannot change the code that I have provided.
If there is a way to have a different function, that will work along side the existing function, that i am fine with that.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
aikimark

Let's start with this function
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

Open in new window

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

Open in new window

Wayne Barron

ASKER
I tried to run the script, but it gave me an error on the first line.

Microsoft VBScript compilation error '800a03f2'
Expected identifier
/spotlight/test/regex2.asp, line 2

Function ReplaceTags(parmString, parmPattern, parmTransformType, Optional parmValue, Optional parmInterval = "yyyy")
-----------------------------------------------------------------^

it is pointing at the                                               Optional parmValue
-----------------------------------------------------------------^

<%
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%>

Open in new window

aikimark

remove the Optional keywords
pass some value for all parameters
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
OK, I got passed all the errors, and commented them out, or removed them.
Now, how do you use this?
If I do
RepalceTags(strDoc)
It gives an error...

Demonstration on how to use this would be helpful.
aikimark

Look at the second routine I posted in prior comment for invocation examples.  Note that all parameters are required, since "Optional" parameters are not allowed in VBScript.
Wayne Barron

ASKER
I looked at the second routine... The SUB.
However, I have no idea on how to pass it.
I tried:  repalceTags(strDoc)
Of which, I would assume that it would work, however, it is giving me
>>> Wrong number of arguments or invalid property assignment: 'ReplaceTags'

So, i am at a loss here Aik.
Your help has saved me hundreds of hours of internet surfing.
fblack61
aikimark

Show me the code that you are using.  I would expect your code to be a version of the statements I posted.
Wayne Barron

ASKER
I posted it above.
It is your code, I am just trying to test it out, and so far... No go.

<%
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)%>

Open in new window

aikimark

Is this the right way to use the function???
<%=ReplaceTags(strDoc)%>
No.  Look at the statements inside the Q_28915256 routine.
strDoc = ReplaceTags(strDoc, "\[theWhole:([^|]*)\|toDate\]", "DateDifference", Date, "d")

Open in new window

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
I do not know how to get it to output.
What do you use to get the results?
What are you doing here?
I am completely lost, and I have never been this lost.
It might be simple to you, however, I do not get it.

You tell me to look at the Q_28915256 routine.
However, that does not tell me, how to get the results out.

If I do a
response.write(strDoc)
Nothing appears.

I DO NOT know how to get this code to work.
All I am asking you, if to Demonstrate, HOW to use this code that you have provided.
aikimark

Since I do not have an ASP environment, I can not provide you code that I have tested.  You might try something like this:
<%
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)
%>

Open in new window

Wayne Barron

ASKER
Nope.
I guess the only option is to request attention, and have someone come in, that can get your code to work. If it works, since you was not able to test it out before posting.

I do appreciate your assistance.
I just hope someone can cipher it, and get it to work.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
aikimark

I most certainly did test it, just not in an ASP environment.
Wayne Barron

ASKER
Of course you tested, however, you did not test it in the environment, that I need it tested in.
I really do appreciate your assistance aikimark.
However, unless I can test the code, and see how it works, it is not useful.
aikimark

Do  you understand what a function is an how it is used?
You should test this
<%
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)%>

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
Running what you just provided.
Wrong number of arguments or invalid property assignment: 'ReplaceTags'
On this line.
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date)

And yes, I know how to use a function.
However, when I cannot get a function to work, then, no, I then, do not know how to use it.
aikimark

I thought I had changed that earlier.  The state should be something like this:
strDoc = ReplaceTags(strDoc, "\[BusDate\]", "RepAllMatchesWithValue", Date, "d")

Open in new window


The ReplaceTags() function takes five parameters.
Wayne Barron

ASKER
Same error
strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Wayne Barron

ASKER
I changed the code to be like the other one.
 strDoc = ReplaceTags(strDoc, "\[theDate:(\d+)\|(\d+)\]", "RepMatchWithSubmatchDifference", Date, "d")

And then it gives me the same error on this line.
<%=ReplaceTags(Q_28915256)%>

Error Code
Wrong number of arguments or invalid property assignment: 'ReplaceTags'
aikimark

look closely at the code I posted
ASKER CERTIFIED SOLUTION
aikimark

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
Works.
Now I just have to make sure that I can make it work for what I need.

Thanks for your assistance, on getting this working.
I will update this topic if there is any issues that I might run into.
Hopefully none.

Carrzkiss
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
For those that may need to use it like me, this is a working example.
Great code aikimark.
The next step, is to make it work within my project.

Carrzkiss
<%
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)%>

Open in new window

Wayne Barron

ASKER
Welp. I got it to work, however, the issue is this.
The tags HAVE to be in every article, in order for it to process the script.
If a tag is missing, it will NOT process the page.

So. I am at a loss.
I have over 135 pages already in the database, and not all of these pages, will utilize these tags.
So.
Any idea's on how to make it work without the tags having to be in every page?

The example #1 works
The example #2 DOES NOT work, it is missing a tag.
<%
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)%>

Open in new window

aikimark

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

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Wayne Barron

ASKER
Very nice, I compared the codes to see what had change.

   Else
        ReplaceTags = parmString

That should wrap it up.
Thank a bunch aikimark.
May you have a rockin weekend my friend.

Carrzkiss
Wayne Barron

ASKER
Here is a complete working code, with the added change to make it NOT require a tag.
Also.
Question: The   toDate
Where is it getting its value from?

<%
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)%>

Open in new window

Wayne Barron

ASKER
I got it..

theDate = Date

I totally overlooked that one.

Good coding.
Have a good one.

Carrzkiss
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

the date value is being passed into the function as the parmValue parameter
Wayne Barron

ASKER
Nice, thank you Aik.
Wayne Barron

ASKER
Aik, got a quick (hopefully) question for you.

This line here

strString = ReplaceTags(strString, "\[birthDate:(\d{4}-\d{1,2}-\d{1,2})\|toDate\]", "AgeAtDate", Date, "yyyy")

Is there any way to wrap it with a <time></time> tag?
This is what I need to happen, when this tag is used in the article.

<time itemprop="birthday" datetime="1971-2-19">44</time>

So, that when you type in the date:  [birthDate:1971-2-19|toDate]

If you have an idea', would love to hear it.

Wayne
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
aikimark


So, that when you type in the date:  [birthDate:1971-2-19|toDate]

If you have an idea', would love to hear it.
Not sure I understand the time tag question.  This sentence doesn't make much sense to me.  Can you rephrase it?