0

I want to extract from a string which looks like this

Something<p class=text>Description</p>Something

just a "Description". I've tried this p class=text>[^<\/p]* and this p class=text>[^<]\/p* but none of that is working. How to achieve that ?

JohnnyGat
  • 325
  • 2
  • 13

1 Answers1

2

You don't need to match the entire class="text":

<p.*?>(.*?)<\/p>

The match group is the tag content. It's simply a lazy quantifier so it doesn't capture the next < (and what follows after that).

slhck
  • 36,575
  • 28
  • 148
  • 201
  • Thanks ! Could you tell me is there a way to instantly put everything between those two tags into variable ? Something like $description<\/p> – JohnnyGat May 24 '15 at 13:29
  • See http://stackoverflow.com/questions/9303984/ruby-regexp-group-matching-assign-variables-on-1-line – slhck May 24 '15 at 15:56