The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Exression Help
Discuss Exression Help in the Regex Programming forum on Dev Shed. Exression Help Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 18th, 2012, 09:23 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Posts: 33
Time spent in forums: 7 h 14 m 2 sec
Reputation Power: 10
|
|
|
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"> </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"> </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"> </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 img</span><br class="c">
</p>
|

April 18th, 2012, 09:29 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
So you want to pay somebody to answer a question that a potential employer asked you specifically?
|

April 18th, 2012, 09:52 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Posts: 33
Time spent in forums: 7 h 14 m 2 sec
Reputation Power: 10
|
|
|
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.
|

April 18th, 2012, 10:09 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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
Quote: | 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.
|

April 18th, 2012, 10:21 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Posts: 33
Time spent in forums: 7 h 14 m 2 sec
Reputation Power: 10
|
|
|
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.
|

April 18th, 2012, 11:53 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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"> </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)
|

April 18th, 2012, 02:01 PM
|
|
Contributing User
|
|
Join Date: Nov 2003
Posts: 33
Time spent in forums: 7 h 14 m 2 sec
Reputation Power: 10
|
|
|
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....
|

April 18th, 2012, 09:43 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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""> </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>";
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|