Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 29th, 2004, 04:52 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert variable value into regex.pattern?

I am building a web search function for our site and want to highlight the word/phrase a user requested on the results page just like this site uses.

I have the code which works but only if you hard code the search criteria which obviously won't work for a search page. What I want to do is insert the value of a variable in the code for the pattern below where it says VARIABLE.

regEx.Pattern = "(\b[a-zA-Z\._]?VARIABLE)"

I have tried using response.write(VARIABLE) but no luck - it appears that regex.pattern only wants to see literal values.

Thanks
 
Old December 30th, 2004, 01:10 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

I just got this from 4guysfromrolla ... check whether this would help you in any way ...

*****Code STARTS here*****
Function Highlight(Search_Str as String, _
                   InputTxt as String, _
                   StartTag as String, _
                   EndTag as String) As String

  Dim ResultStr As String
  Return Regex.Replace(InputTxt, "\b(" & Regex.Escape(Search_Str) & ")\b", _
           StartTag & "$1" & EndTag, RegExOptions.IgnoreCase)
End Function
*****Code ENDS here*****

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old December 30th, 2004, 08:43 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Vadivel - I'll try some variation of that code which looks like it accepts a VARIABLE by using regex.escape.
 
Old January 3rd, 2005, 05:07 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still no luck. Where did you get that code? I tried looking on the 4 Guys site but could not find it. Perhaps if I had the rest of the code in the example and not just the function it would be helpful.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using INSERT INTO with a string Variable Suspect Access VBA 2 January 6th, 2015 11:25 AM
Insert Variable Value into DB Deano252 ASP.NET 2.0 Basics 1 June 24th, 2006 03:21 AM
Using SQL Insert into with a variable erichoangnguyen Access VBA 3 May 3rd, 2005 01:40 PM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM
insert value of variable into an existing table mountaindew7612 SQL Server 2000 5 October 16th, 2004 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.