Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

Regex Puzzle.. :(

This topic is 2901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 = "<a href=/part/of/some/dir/hello.wow/23423134/sdfj2k34j23k4j3d/$TheFile/234-023.2.1991.pdf\\";

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?

Share this post

Link to post
Share on other sites
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.


<a href="http://www.gamedev.net">Click Here</a>

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


Here is the code I used for that:

foreach (Match match in Regex.Matches(sampleTextToParse, "<a href='(.*)'>(.*)</a>", 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.

Share this post

Link to post
Share on other sites
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!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!