Code
6.1
</td>
i have this in a website source and im using this to capture the 6.1:
Code Dim r As New System.Text.RegularExpressions.Regex(" ([^""]*)</td>")
Dim matches As MatchCollection = r.Matches(response)
For Each match As Match In matches
captureee = match.Value.ToString()
Next
Dim capturee As String = captureee.Replace(" ", "")
Dim capture As String = capturee.Replace("</td>", "")
Dim cap As String = capture.Replace(" ", "")
Dim finalcap As String = Regex.Replace(cap, "^\s+$[\r\n]*", "", RegexOptions.Multiline)
But this returns the 6.1 With another blank line.. and i cant use the blank line...
You can of course Trim the result. But eh... you really shouldn't be using regex to "parse" HTML.
(Jan 5, 2018 07:14 AM)Dialog Wrote: You can of course Trim the result. But eh... you really shouldn't be using regex to "parse" HTML.
What else then?
(Jan 5, 2018 08:23 AM)Soldiercrimes Wrote: What else then?
HTML parsers sound like they're decent at parsing HTML. Consider HTML Agility Pack: http://html-agility-pack.net/.
(Jan 5, 2018 08:26 AM)Dialog Wrote: HTML parsers sound like they're decent at parsing HTML. Consider HTML Agility Pack: http://html-agility-pack.net/.
Hmm regex and Trim() do the job for now :p thanks dude
(Jan 5, 2018 07:14 AM)Dialog Wrote: You can of course Trim the result. But eh... you really shouldn't be using regex to "parse" HTML.
Dialog is right, regex is for "regulair text" which html is not, regex is not self correcting or forgiven for mistakes in the markup, it is not recommended.
Jan 5, 2018 02:28 PM
(This post was last modified: Jan 5, 2018 02:32 PM by System[X].)
Quickly done this but not tested.
Regex pattern
Code " (\n+\s+)(\d\.\d)(\n+\s+)</td>"
Then use match.Value(2)
Thanks
Edit: depending on the rest of the html code you could just use (\d\.\d) but if there are more number.number sequence it wont work
(Jan 5, 2018 02:28 PM)System[X] Wrote: Quickly done this but not tested.
Regex pattern
Code " (\n+\s+)(\d\.\d)(\n+\s+)</td>"
Then use match.Value(2)
Thanks
Edit: depending on the rest of the html code you could just use (\d\.\d) but if there are more number.number sequence it wont work
Thanks for the tip man, it's already working with the Trim function but I will keep this in mind.
(Jan 5, 2018 03:13 PM)Soldiercrimes Wrote: Thanks for the tip man, it's already working with the Trim function but I will keep this in mind.
Using a better regex pattern removes the need to use Trim or Split but then again Trim and Split is only an extra 2 lines of code :)
Thanks
(Jan 5, 2018 03:35 PM)System[X] Wrote: Using a better regex pattern removes the need to use Trim or Split but then again Trim and Split is only an extra 2 lines of code :)
Thanks
Using regex to parse HTML is for retards.
DO NOT DEAL WITH THIS MEMBER
(Jan 5, 2018 04:55 PM)Dialog Wrote: Using regex to parse HTML is for retards.
If it is a long document and you need a single string parsed then it is not always bad to use.
(Jan 5, 2018 05:20 PM)Ninja Wrote: If it is a long document and you need a single string parsed then it is not always bad to use.
Yes it is always bad to use.
Learn how to use xpath instead.
DO NOT DEAL WITH THIS MEMBER
(Jan 5, 2018 06:40 PM)Fire Wrote: Learn how to use xpath instead.
HtmlAgilityPack has XPath, and Chrome has an option where you can right click an element and select "copy as XPath" or something like that.
(Jan 5, 2018 04:55 PM)Dialog Wrote: Using regex to parse HTML is for retards.
How is it not good to use regex for a simple task like this just to grab "6.1" ?
Yes lets make it better by using the agility pack but over complicates things when a single regex pattern can do the job just as good.
ll it comes down to is what you prefer and we all prefer different approaches to solve tasks.
Thanks
|