Skip to main content
GameDev.net gamedev.net
🔒 Locked

Regex Puzzle.. :(

Started by Instigator Nov 10, 2011 at 6:47 PM 1 replies 1k views
Original Post
Instigator
Instigator
Hi Guys,

I'm trying to grab a pdf location from a webpage ->

Here is part of the html code I am looking through:

string sampleTextToParse = "


My Regex below can so far pickup "/$TheFile/234-023.2.1991.pdf"

string picksUpEnd = "([/][$]TheFILE[/].{5,}(?=\\.pdf))";
string test = Regex.Match(sampleTextToParse, picksUpEnd);
test += ".pdf";


BUT I also have to get all text before this to the 'href=/' marker. So I believe behindlookup is the solution.
.
.
I tried

string picksUpPath = "([/][$]TheFILE[/].{5,}(?=\\.pdf))(?<=href)=";

but this does not seem to return anything in my Regex.Match method..

Any ideas to solve this Regex problem?
CyberJay82
CyberJay82
I used something similar to help strip html links out of a document and just replace the whole html tag with just the href part.

Example:

Click Here

I would strip out the http://www.gamedev.net part and the new text would just become

http://www.gamedev.net

Here is the code I used for that:

foreach (Match match in Regex.Matches(sampleTextToParse, "(.*)", RegexOptions.IgnoreCase))
if (match.Groups.Count > 1)
sampleTextToParse = sampleTextToParse.Replace(match.Groups[0].Value, match.Groups[1].Value);


I hope this helps you get what you need.
Its not a bug, its a feature!!
Instigator
Instigator
Okay, thanks..

I used some of your content to provide myself with a solution

Here's my answer if anyone needs to know for future


string regex = "(?<=href=)([a-zA-Z0-9/\\._]*)([$]TheFILE[/]).{5,}(?=\\.pdf)"


Damn Regex is so awesome!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.