PDA

View Full Version : need regular expression


Dee99
11-08-2010, 10:34 PM
can anyone provide a vbscript regular expression pattern to extract text highlighted in red from this line of html ?

<input type="hidden" name="cmd" value="item">

Old Pedant
11-08-2010, 11:17 PM
html = "<form>" & vbNewLine & "<input name=""foo"">" & vbNewLine _
& "<input type=""hidden"" name=""cmd"" value=""wombats triumph"" class=""xyz"">" _
& vbNewLine & "</form>"
Set vre = New RegExp
vre.pattern = "(^[\s\S]*?\<input\s.*?name=\""cmd\"".*?)(value=\""[^\""]*\"")([\s\S]*$)"
vre.ignoreCase = True

findit = vre.Replace( html, "$2" )

Response.Write "<HR>" & findit & "<HR>"

That code is insisting on seeing
<input
name="cmd"
value="..."
in that order.

If it's possible that the value= might appear before the name=, we'd need to add to it.

If it's important that we find
type="hidden"
and if that might appear at various places in the <input>, then that complicates things, too.

But this should give you a starting point.

Old Pedant
11-08-2010, 11:20 PM
And if you really wanted to ONLY find
wombats triumph
just change the pattern to
vre.pattern = "(^[\s\S]*?\<input\s.*?name=\""cmd\"".*?value=\"")([^\""]*)(\""[\s\S]*$)"