#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Cincinnati, Ohio
    Posts
    25
    Rep Power
    0

    Question Regular Expressions & Replace Method


    Problem: I want to check the data from a RecordSet.GetString result for today's date. If today's date exists in the row then I want to replace the preceeding <tr> tag with a <tr style='background:grey'>. I made the following objRegExp.Pattern:

    Code:
    .Pattern		= "\<tr\>\<td\>\<font size=\'1\'\>[\w]*\<\/font\>\<\/td\>\<td\>\<font size=\'1\'\>[\w]*\<\/font\>\<\/td\>\<td\>\<font size=\'1\'>" & FormatDateTime(now(),vbShortDate)
    This successfully identifies the row as containing today's date. Yea! Now, the replace part.

    Code:
    text = objRegExp.Replace(text,"<tr style='background:grey'><td><font size='1'></font></td><td><font size='1'></font></td><td><font size='1'>" & FormatDateTime(now(),vbShortDate))
    This piece works except I lose the data that was actually contained in each cell. How can I have it so that the only thing that gets replaced is the table row tag?

    Regards,

    dot
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    NJ
    Posts
    428
    Rep Power
    17
    You need to use remembered matches. I think i'm understanding you correctly. Try something like this.

    PHP Code:
    .pattern "\<tr\>(\<td\>\<font size='1'\>[\w]*\<\/font\>\<\/td\>\<td\>\<font size='1'\>[\w]*\<\/font\>\<\/td\>\<td\>\<font size='1'>" FormatDateTime(now(),vbShortDate) & ")" 
    note the parens. This tells the regexp engine to remember parts of the match. Then your replace would be something like this

    PHP Code:
    .Replace(text,"<tr style='background:grey'>$1"
    the $1 will insert the remembered section.

    Hope this works
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Cincinnati, Ohio
    Posts
    25
    Rep Power
    0
    Thank you. That worked *exactly* as I needed it to. I had been researching the remembered matches, but hadn't found a referece to the () making the $1 ... n pieces the actual matches.

    Regards,

    dot

IMN logo majestic logo threadwatch logo seochat tools logo