0

How do I make a match in a string to very first occurence of a character in a multi line file for example if i have


$3.95 (html tags) $2.95

(html tags) (html tags) Red door

(html tags)

I want to just extract


$2.95

(html tags) (html tags)

Red door

So i want it to stop at the previous $, i tried something like \$[\s\S]*Red door, however that goes too far back, some asked for more specifics..

So here is a page on amazon, I want to pull out just the section sold and shipped by amazon: http://www.amazon.com/gp/offer-listing/B00XR5HRBU/ref=dp_olp_new?ie=UTF8&condition=new, I can easily go to alt="Amazon.com and then back up to the first $ which would do this.

  • Regex is not the right tool for the job - use html parser! – Nir Alfasi Oct 21 '15 at 19:30
  • Show the exact html codes. There's nothing we can do for you, if the code is this vague. – frosty Oct 21 '15 at 19:44
  • I need to use regex. http://www.amazon.com/gp/offer-listing/B00XR5HRBU/ref=dp_olp_new?ie=UTF8&condition=new for example I want to pull out the section with just amazon has sold and shipped by them, so i can get the price, etc. – Preston Garrison Oct 21 '15 at 19:56
  • That's all findable with a parser. The first entry on the page you cite that is run by amazon has `
    $259.00 ....
    – Shawn Mehan Oct 21 '15 at 20:07
  • See: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags for why you shouldn't use `regex` to parse `html`. (It's because pretty fundamentally - the 'scope' of what regex can handle is smaller than the scope of what can be expressed in HTML) – Sobrique Oct 21 '15 at 20:10
  • I can not go into the reasons why html parsing would not work for this, but there are reasons why its not a good solution in the long term. – Preston Garrison Oct 21 '15 at 20:20

1 Answers1

0

A better tool for the job would be an HTML parser. But if you must, you can try to just not match another $ in the middle:

\$[^$]*Red door
davidrac
  • 10,723
  • 3
  • 39
  • 71
  • While that does seem to work it makes me realize I actually need to go back to the following string olpOfferPrice a-text-bold"> $ is it possible to do that with first occurrence? – Preston Garrison Oct 21 '15 at 20:20