:
: "Roland Hall" wrote:
: > "Miguel Orrego" wrote:
: > : I have a variable in an app called GenericTitle which contains text,
: a
: > : persons job title funnily enough.
: > :
: > : I want to check whether this variable contains the word "director"
: and if
: > it
: > : does, then redirect to another page for example.
: > :
: > : Can somebody post some code that would let me check this?
: >
: > with regular expressions
: >
: > <%@ Language=VBScript %>
: > <%
: > Option Explicit
: > Response.Buffer = True
: >
: > sub getTitle(strTitle, go, goelse)
: > Dim re, str, em
: > str = "director"
: > Set re = new RegExp
: > With re
: > .Pattern = "(\w)+"
: > .IgnoreCase = True
: > .Global = false
: > End With
: > Set em = re.Execute(strTitle)
: > if lcase(em(0)) = "director" then
: > Response.Redirect(go) ' director
: > else
: > Response.Redirect(goelse) ' not director
: > end if
: > set re = nothing
: > end sub
: >
: > dim GenericTitle
: > GenericTitle = Request.QueryString("gt")
: > getTitle "" & GenericTitle & "", "
http://wallstreet.com/",
: > "
http://disney.com"
: > %>
:
: The above code only works when the title begins with the word
: "director". Here are some false negatives that your code does not
: capture:
:
: assistant director
: assistant_director
: director_of_photography
: directory
:
: Here's an alternative function:
: <%
: Function IsDirector(str)
: Dim re,retVal
: Set re = New RegExp
: With re
: .Global = True
: .IgnoreCase = True
: .Pattern = "director"
: retVal = .Test(str)
: End With
: Set re = Nothing
: IsDirector = retVal
: End Function
: %>
:
: Also note that from a performance standpoint, it can be inefficient to
: instantiate a RegExp object if it's only going to be used once. The
: merits of regular expression objects lie in their robust pattern
: matching capabilities and the economies of scale that come into play
: when the strings being matches are many or large.
I missed the word contains in the OPs post, I thought it was equal.
Are you telling me the regular expression has a lot of overhead and should
only be considered when it is a global search?
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp