View Full Version : need regexp help
ecnarongi
05-21-2003, 09:33 PM
How do I use the regexp object to grab "June" from "June 2003" or "May" from "May 2004" or any month from any date? then I want to store that in a separate variable. All help is appreciated, thanks.
oracleguy
05-22-2003, 01:52 AM
Couldn't you just use the Month(Date) method instead?
Bullschmidt
05-22-2003, 04:04 AM
Or you could use InStr() to get the place of the first space and then Left() everything up to that.
Or you could Split() on the " " into an array and take the first value in the array.
oracleguy
05-22-2003, 05:17 AM
But if you really wanted to use regular expressions, you could try the pattern, ". " thats a period and then a space, just to clarify.
ecnarongi
05-22-2003, 03:12 PM
thanks :thumbsup:
ecnarongi
05-23-2003, 03:56 PM
I tired the above and it didn't work. here is my code:
strHTML = request.form("name")
Dim objregexp
Set objregexp = New regexp
objregexp.IgnoreCase = True
objregexp.Global = True
objregexp.Pattern = "/[^ ]+^/"
strText = objregexp.Replace(strHTML, "This is a month")
response.write srtText & strHTML
where name is that date passed by a form formatted like "June 2003". this example only yields me whatever the value of name was. can anyone help me on this, all help is appreciated, thanks.
ecnarongi
05-23-2003, 04:32 PM
I used this to do the same but I thought a reg exp would be better
strHTML = request.form("name")
val = instr( strHTML, " ")
olddate = left( strHTML, formatnumber(val)-1)
newdate = replace( strHTML, olddate, "this is a month")
Response.write "this is the orgin = " & strHTML & "<br>"
response.write "this is the new = " & newdate & "<br>"
I guess I don't need the reg exp. :D
whammy
05-24-2003, 12:34 AM
If your date is in this format:
May 2004
Why not just use split? i.e.:
DateSplit = Split("May 2004"," ")
Month = DateSplit(0)
ecnarongi
05-27-2003, 03:44 PM
because I actually need to replace the month in the date. I have to get the value, hopefully the month is first, then replace it so that I can sort the collection of them later.
whammy
05-28-2003, 12:26 AM
Hmm, so you could still do it that way... anyway, this is one case where I don't necessarily see a regex helping - although you could still use it...
"May 2004" =
^(\w+)\s\d{4}$
Now that you've grouped the month with (), you can just replace that (with another function that replaces each month with its numerical value or something). Of course, you could use split() or other string manipulation methods to accomplish this same thing very easily.
:D
whammy
05-28-2003, 12:28 AM
P.S. Just out of curiousity, why do you want month in a separate variable?
I'd just use a DateTime field (that way you can sort by seconds or even milliseconds, I believe, if you so desire - using CONVERTDATETIME() or BETWEEN or whatever!), and if you need to sort by month use the DatePart() function... i.e.
...WHERE DatePart(Month,someDate) = 12 AND ...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.