Thread: Exression Help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    33
    Rep Power
    11

    Exression Help


    Hello everyone I'm super new to Regular Expressions. I need an expression that will pickout the text from the paragraphs in html markup like the snippet shown below. I would pay someone through paypal or vworker but I don't have a cent right now and super duper need this to get a tutorial to work. I need this for a job interview that I'm going to attend tommorow Thursday. I promise to pay you when I have money in my paypal account on May 7th if that's what it takes. And if that's what it takes then let me know how much you would require. You can email me at juan.matos@juanmatos.net here's the snippet:
    Code:
    <p class="row">
    			<span class="ih" id="images:5N25Gf5F13Ga3M23Ffc3u3b475684d2051dd4.jpg">&nbsp;</span>
    			 Apr 18 - <a href="http://miami.craigslist.org/mdc/cto/2912842874.html">96 bronco must sale stong truck -</a>
    			 $2600<font size="-1"> (homestead)</font> <small class="gc"><a href="/cto/">owner</a></small> <span class="p"> pic</span><br class="c">
    		</p>
    		<p class="row">
    			<span class="ih" id="images:5Ia5K85H13I43Jc3Hcc4ae516ae209bf414f3.jpg">&nbsp;</span>
    			 Apr 18 - <a href="http://miami.craigslist.org/brw/cto/2951611980.html">Ford F250 Diesel Truck  -</a>
    			 $3500<font size="-1"> (pompano beach)</font> <small class="gc"><a href="/cto/">owner</a></small> <span class="p"> pic</span><br class="c">
    		</p>
    		<p class="row">
    			<span class="ih" id="images:5Hf5X45J63F23I83N2c4iec514f9df8b61810.jpg">&nbsp;</span>
    			 Apr 18 - <a href="http://miami.craigslist.org/mdc/cto/2964917755.html">BLUE TRUCK FORD F150 -</a>
    			 $2149<font size="-1"> (MIAMI (CUTLERBAY))</font> <small class="gc"><a href="/cto/">owner</a></small> <span class="p"> pic&nbsp;img</span><br class="c">
    		</p>
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    So you want to pay somebody to answer a question that a potential employer asked you specifically?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    33
    Rep Power
    11
    It would be so refreshing to see a decline in replies from ppl on forums who come across as stupid. To read into my original post and come to assume that the interview has to do my ability to write a regular exrpession makes me wonder how such a person even gets through the day without accidently stepping off the curb in front of a speeding car. The tutorial is about A, B, C and D. My responsibilty at the job should i get it has to do with A and B. The Regular Expression in the tutorial which is outdate would be the "C" part. And that part is not necessary for me to know for to do my job. But that "C" part is needed to get the whole program to function. So that as a whole I can understand what I need to know. I have a friendwho always assumes that a car slowing down to make a right hand turn is going to make the right hand turn when the care has slowed down to about 10 mph right at the turn. But sometimes the driver that is showing that he is going to turn just suddenly stops. My friend will hit this guy 9 out of 10 times. He always makes the assumtion that that car is going to turn. He's STUPID as far as I'm concerned.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    A simple "no" would have sufficed. I'd rather not have to break down my response into the individual components of your post that I was directing it at. But I will say
    Originally Posted by matos240
    I have a friendwho always assumes that a car slowing down to make a right hand turn is going to make the right hand turn when the care has slowed down to about 10 mph right at the turn. But sometimes the driver that is showing that he is going to turn just suddenly stops. My friend will hit this guy 9 out of 10 times. He always makes the assumtion that that car is going to turn. He's STUPID as far as I'm concerned.
    Glad I'm not your friend then.


    Regex isn't the best choice for dealing with HTML. Does it have to be a regex?
    Last edited by requinix; April 18th, 2012 at 10:11 AM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    33
    Rep Power
    11
    I'm sorry I went off. But I took that remark as an indication that what I was doing as unethical, shady, mis-honest...And I don't take well to that kind of poking. That is one of my character flaws I guess. But to answer your question yes because most of the code is written around this assumption.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    You have to admit that things like "I need this for a job interview" sound a certain way...


    Well at least the HTML looks very uniform. When I write regular expressions for things like this I prefer to be very specific and use as few wildcards as possible, so
    Code:
    <p class="row">\s+
    <span class="ih" id="images:[a-z0-9]+.jpg">&nbsp;</span>\s+
    (... ..) - <a href="http://miami.craigslist.org/[a-z]+/cto/\d+.html">(.*?) -</a>\s+
    (\$\d+)<font size="-1"> (.*?)</font> <small class="gc"><a href="/cto/">owner</a></small> <span class="p">.*?</span><br class="c">\s+
    </p>
    - I left it spanning multiple lines for the sake of reading it in this post. You'll probably want to collapse it all into one line
    - You can throw in a few more capturing groups for things like links or images if you want
    - Also feel free to substitute out some of the HTML for .*?s
    - If you have to wrap delimiters around it, don't forget to escape any inside the expression (like the few slashes in there)
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    33
    Rep Power
    11
    I tried your expression but it has lots that isn't liked by the compiler. I tried playing around for it but for now this is beyond my capabilities. But super duper thanks for what you have done so far and I belive i have avoided the Regular Expression learning long enough and it's time to learn it. Folks the expression from the tutorial is this one.

    string expression = @"<p>[^<]*<a[^>]*>(?<item>[^<]*)</a>";

    But it seems that the Craigslist format is different now. This tutorial posting is 3 years ago. So it doesn't work anymore. I provide the expression so that it may give an idea of how to go about this. Super please....
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    C#? My expression as written for the language would be
    Code:
    string expression = @"<p class=""row"">\s+<span class=""ih"" id="images:[a-z0-9]+.jpg"">&nbsp;</span>\s+(... ..) - <a href=""http://miami.craigslist.org/[a-z]+/cto/\d+.html"">(.*?) -</a>\s+(\$\d+)<font size=""-1""> (.*?)</font> <small class=""gc""><a href=""/cto/"">owner</a></small> <span class=""p"">.*?</span><br class=""c"">\s+</p>";

IMN logo majestic logo threadwatch logo seochat tools logo