troubleshooting Question

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

Avatar of Wayne Barron
Wayne BarronFlag for United States of America asked on
ASPVisual Basic ClassicVB Script
47 Comments1 Solution233 ViewsLast Modified:
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)
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)%>

I know there has to be a way to do this.
Any idea's?
Get vaccinated; Social distance; Wear a mask
Join our community to see this answer!
Unlock 1 Answer and 47 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 47 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros