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:
For Each item In Request.Form
searchFor = "name=""" & item & """ value="""""
replStr = "name=""" & item & """ value=""" & Request("" & item & "") & """"
TitleInfo.InnerHtml = TitleInfo.InnerHtml.Replace(searchFor, replStr)
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.
Re: Regular Expression with Variables
You could try
TileInfo.InnerHtml = System.Text.RegularExpressions.Regex.Match(TitleInfo.InnerHtml,"name=.+?value="").ToString & Request(item)
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.
Re: Regular Expression with Variables
Regex.Match(TitleInfo.InnerHtml,"name=" & item & "value="").ToString & Request(item)[/QUOTE]
Re: Regular Expression with Variables
Does not work.
I get an error:
Regex.Match cannot be converted to string.