Results 1 to 5 of 5

Thread: Regular Expression with Variables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2003
    Posts
    232

    Regular Expression with Variables

    Hi,
    I am trying to do something pretty simple, but i am not sure how to do it with .NET regular expressions. I've used regular expressions in perl alot.

    I have an aspx page which i keep on refreshing, and the values can be changed by the user each time it refreshes. However the values that the user puts in do not get saved so what i do is , in my .VB code i do a loop through all the request form values and i search for name equal to that item and i want to replace it with the values. so it will get displayed properly.
    how do i search for something using a variable???
    here is my code:

    VB Code:
    1. For Each item In Request.Form
    2.             searchFor = "name=""" & item & """ value="""""
    3.             replStr = "name=""" & item & """ value=""" & Request("" & item & "") & """"
    4.              TitleInfo.InnerHtml = TitleInfo.InnerHtml.Replace(searchFor, replStr)
    5.         Next

    my problem is i want to put something like a * in the value.
    I want to say any line that says "name=varname value=[ANY VALUE] replace with name=varname value=request(varname).
    how do i do that??

    ANy help would be grealty appreciated.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Regular Expression with Variables

    You could try

    TileInfo.InnerHtml = System.Text.RegularExpressions.Regex.Match(TitleInfo.InnerHtml,"name=.+?value="").ToString & Request(item)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2003
    Posts
    232

    Re: Regular Expression with Variables

    Since there are a few name= value=, i need the regular expression to contain the item variable too. name = item. Can you add that to the example that you gave?
    THanks.

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Regular Expression with Variables

    Regex.Match(TitleInfo.InnerHtml,"name=" & item & "value="").ToString & Request(item)[/QUOTE]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2003
    Posts
    232

    Re: Regular Expression with Variables

    Does not work.
    I get an error:
    Regex.Match cannot be converted to string.

Posting Permissions

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



Click Here to Expand Forum to Full Width