CipherIS
asked on
VB.NET Regex <span class=bld>\s*(.+?)\s*</span>
Troubleshooting a piece of code.
My question is what does "<span class=bld>\s*(.+?)\s*</spa n>", RegexOptions.Singleline" do?
Dim web As Net.WebClient = New Net.WebClient()
Dim html As String = web.DownloadString("https://www.google.com/finance/converter?a=1&from=EUR&to=USD")
Dim m1 As Match = Regex.Match(html, "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline)
Dim currency As String = m1.Groups(1).Value.Replace("USD", "")
user.setEuro(Convert.ToDouble(currency))
currency is blank. My question is what does "<span class=bld>\s*(.+?)\s*</spa
ASKER
Little confused. You suggested to use <span class=bld>\s*(.+?)\s*</spa n>. But that is exactly what is being used in the Regex.
Dim m1 As Match = Regex.Match(html, "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline)
No at the end the / is escaped by a \
<\/span>
I am not sure if regex in .net "/" needs to be escaped
ASKER
Ah. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi CipherIS;
The reason why you are getting the "currency is blank" is that there is no tag in the html that has this in it, <span class=bld>, therefore the variable m1 is empty.
If this was working before maybe they changed the format of the html?
The reason why you are getting the "currency is blank" is that there is no tag in the html that has this in it, <span class=bld>, therefore the variable m1 is empty.
If this was working before maybe they changed the format of the html?
This regular expression try to find then html element enclosed in
Open in new window
andOpen in new window
but it seems wrongtry instead
Open in new window
refer tohttps://regex101.com/r/E2Z4hX/1
Open in new window
is the part in parenthesis - (.+?) - to be changed where "USD" is replaced with nothing("")Regards