Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

C# Regex for URL Grabbing

Hi all, I need to grab some URL's from a page source code and am trying to do so using regex. I am not very familiar with regex and have only used it a couple times. Here is the section of the code from which I am trying to grab the links from:

Code
<script type="application/ld+json">
       {"@context":"http:\/\/schema.org","@type":"ItemList","mainEntityOfPage":{"@type":"CollectionPage","@id":"https:\/\/9gag.com\/germany"},"itemListElement":[{"@type":"ListItem","position":1,"url":"https:\/\/9gag.com\/gag\/aV0qvqn\/zufalliger-diskussionsthread-sep-30-oct-6"},{"@type":"ListItem","position":2,"url":"https:\/\/9gag.com\/gag\/a3RMy45\/fang-mal-auf"},{"@type":"ListItem","position":3,"url":"https:\/\/9gag.com\/gag\/ag5Y8Nr\/vielleicht-hast-jemand-verwendung-fur-in-der-diskussionsrunde"},{"@type":"ListItem","position":4,"url":"https:\/\/9gag.com\/gag\/az1qK6z\/wie-man-jungs-dazu-bringt-in-der-schule-besser-aufzupassen"},{"@type":"ListItem","position":5,"url":"https:\/\/9gag.com\/gag\/aQ1eQY7\/wer-kennt-es-nicht"},{"@type":"ListItem","position":6,"url":"https:\/\/9gag.com\/gag\/aEgBVDM\/harry-potter-themenparks-in-deutschland"},{"@type":"ListItem","position":7,"url":"https:\/\/9gag.com\/gag\/avo7EWZ\/vier-buchstaben"},{"@type":"ListItem","position":8,"url":"https:\/\/9gag.com\/gag\/a5RnBbL\/jedes-mal"},{"@type":"ListItem","position":9,"url":"https:\/\/9gag.com\/gag\/aO0BD9y\/anruf"},{"@type":"ListItem","position":10,"url":"https:\/\/9gag.com\/gag\/aGge8ew\/ja-dann"}]}    </script>

Please note I am parsing an entire page source code(9gag.com/Germany) into a string not just the code above. I would also be fine if I was just able to grab the id in each link such as "aV0qvqn" in the first one. Stack overflow suggested this solution: https://stackoverflow.com/questions/1057...l-urls-but but it does not work. This grabs every link in the source code besides the links I need so I am guessing the "\/\/" and other characters are messing it up? Help would be much appreciated on this, thanks!
Need some code written or help with a programming assignment?
Check out my thread.
Why has nobody suggested decoding the json and getting all the values?


Using NewtonSoft.Json library available in nuget package:

[Image: LBWM9Vn.png]

Also, if you still insist on using Regular Expression to do this, check out this: https://rubular.com/r/iW6y82MjNLRV1y or this https://rubular.com/r/bfwLyXglZwUzzV
[Image: Syr3DlV.png]
(Oct 7, 2019 08:16 PM)gigajew Wrote:  Why has nobody suggested decoding the json and getting all the values?


Using NewtonSoft.Json library available in nuget package:

[Image: LBWM9Vn.png]

Also, if you still insist on using Regular Expression to do this, check out this: https://rubular.com/r/iW6y82MjNLRV1y or this https://rubular.com/r/bfwLyXglZwUzzV

I was literally just checking out this package as I saw you post this lol! Thanks for the response I am working on it now.
Need some code written or help with a programming assignment?
Check out my thread.
Use htmlagilitypack and extract all <a href /> élément !
(Oct 8, 2019 06:59 AM)Fhack Wrote:  Use htmlagilitypack and extract all <a href /> élément !

URL's don't have to always exist in <a> elements or "href" attributes.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
Got it working with gigajew's post. Closing this thread. Thanks everyone for helping out.
Need some code written or help with a programming assignment?
Check out my thread.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by zograJun 18, 2021 09:13 AM 4 128 Jun 18, 2021 09:13 AM
Last Post: zogra
[C#] by ΤmanJan 31, 2017 05:08 PM 11 278 Jan 31, 2017 05:08 PM
Last Post: WinA
[.NET] by dark.teamSep 19, 2015 08:23 AM 8 170 Sep 19, 2015 08:23 AM
Last Post: Temploit