Regular Expressions and Templates

Results 1 to 3 of 3

Thread: Regular Expressions and Templates

  1. #1
    Bradley Guest

    Default Regular Expressions and Templates

    Hi --<BR><BR>I am trying to do something that I thought would ahve been simple, however, the best laid plans... <BR><BR>I can do the template expansion until I try and actually try to use the expansion in a referecne to <BR>a recordset piece (e.g. rs(""$1"") or even rs($1)...<BR><BR>it is obvious that it will not work as typed, but how do I do it to achieve what I have written?<BR><BR>How can I do this? Or what am I oing wrong? Basically it syntax errs when I try to reference the rs stuff. <BR><BR>-- Bradley<BR><BR>I would like a template file that looks like:<BR><BR>--Begin Template.Tmp file<BR>%Name% blah blah blah %Address%<BR>Blah blah blah %City%, %State% %Zip%<BR>--End file<BR><BR>I was planning on expanding it like this:<BR><BR>-- skipping recordset rs stuff --<BR>-- lets just assume it is initialized and --<BR>-- positionned to the current record --<BR><BR>sub OutputRecordFromTemplate(rs)<BR> <BR> dim replStr<BR> dim patStr<BR> <BR> patStr = "%([a-zA-Z0-9]+)%"<BR> <BR> dim regEx<BR> set regEx= new RegExp<BR><BR> regEx.Pattern = patStr<BR> regEx.Global = True<BR> regEx.IgnoreCase = True<BR> <BR> <BR> Dim myText<BR> <BR> Dim fso<BR> set fso = Server.CreateObject("Scripting.FileSystemObject")< BR> <BR> Dim ourtext<BR><BR> set ourtext = fso.GetFile("c: emplate.tmp")<BR><BR> &#039Open a file for reading<BR> set ts = ourtext.OpenAsTextStream(1,-2)<BR> Do while not ts.AtEndOfStream<BR> myText = ts.readline<BR><BR> replStr = "Field $1 =" & rs.Fields.Item($1)<BR> <BR> Response.Write regEx.Replace(myText, replStr)<BR> Loop<BR>end sub<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Regular Expressions and Templates

    Erm, what are you actually trying to achieve here? It&#039s slightly less clear than mud... <BR><BR>Dunc

  3. #3
    Join Date
    Dec 1969

    Default Awesome Idea...

    I think i see what you are trying to pull off. Are you trying to use the $1 as a pattern reference to the field value in the recordset.. so if $1 matched 3 values then you could nail all three in one replace statement. Right? First off let me say Im pretty sure that $1 is only compatible with perl. I believe the javascript regular expression support this and is more "perl" like. But even then I dont see how you could use it in the recordset field. If you figure it out Id be very interested in how you did it. Because I too write templates and if I could nail all my replace statements to one I would be a very happy camper. Send me an email if you figure it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts