0

I want to get this string between the <p> tags here:

                <h2>Description</h2>
        </div>  
        <div class="topIdeasDetailsInner clearfix">
            <p>There is nothing better than a customized sloth! With this app, you can dress up sloths, face-in-a-hole a sloth, and insert the sloth in any pictures. This app will be like having a small version of photoshop on your phone. </p>     
    </div>
    </div>   

In Regexr, I can get that string using the following expression:

<div class="topIdeasDetailsInner clearfix">\n               <p>?[^>]*<\/p>

But when I use it in VB it doesn't really work.

"<div class=""topIdeasDetailsInner clearfix"">\n                <p>(?<Data>[^>]*)<\/p>"

Maybe in VB I need to define the spaces after "\n" with a specific expression? I tried " *" but it didn't work too ...

P.S : I use <Data> to get the value I want so don't mind it.

P.S 2 : Here is the link I try to get my string from if you ever wonder: http://www.preapps.com/app-ideas/topic/41/sloth-me

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Amine Tagui
  • 205
  • 2
  • 13
  • Could be because there's a common understanding that regex [isn't considered the best tool to parse HTML/XML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). It's like asking how to use a pocket knife to cut down trees while you got a chainsaw roaring. – LukStorms May 05 '17 at 09:44
  • I thought that it's the most optimal solution because i only needs few strings from the code ... Is there any better solution for my case ? (And thanks for the answer , now it's working fine) – Amine Tagui May 05 '17 at 15:01
  • No idea. But [here's a an example answer](http://stackoverflow.com/questions/16390441/vb-net-how-do-i-search-through-webpage-source-for-particular-div-and-output-in) using a different method. – LukStorms May 05 '17 at 15:44

1 Answers1

2

You don't need to hardcode the whitespaces.
Just use \s with * (0 or more) or + (1 or more)

<div\s+class="topIdeasDetailsInner clearfix">\s*<p>([^<]*)<\/p>

And surrounding what you need with () will put it into a capture group.

LukStorms
  • 28,916
  • 5
  • 31
  • 45