-3

I want to extract the product name from this string. I basically need to do newtext.match(RegexIdontknow); From Cast - to the three dots.Every thing between > and < without the whitespaces.

P.S:Treat this as a string. I had performance issues when trying to parse it using HTML parser because parsing using HTML parsers hangs the app.I didnt need more than this part of it. After struggling with HTML parsers for React native for many days, I decided to get it as a string, get the part I want and get the product name I am looking for.

`product-title" role="link">



            Cast Iron Square Grill Pan - 10.5 Inch Pre-Seasoned Skillet with...




</span>`
tksilicon
  • 3,276
  • 3
  • 24
  • 36
  • 1
    [Don't parse HTML with Regex](https://stackoverflow.com/a/1732454/107625)! – Uwe Keim Feb 29 '20 at 17:46
  • I captured the string and I want to extract those words. I am not parsing HTML. – tksilicon Feb 29 '20 at 17:48
  • So what is your definition of "parsing"? – Uwe Keim Feb 29 '20 at 17:49
  • This is not html. It is a string. I want to extract product name, I have edited the question. – tksilicon Feb 29 '20 at 17:50
  • 1
    @tksilicon A string can contain HTML and it seems that that is the case. That is what that post is about. Regex is not the right tool for parsing HTML. Use an HTML parser and get the content that way. – Ivar Feb 29 '20 at 18:02
  • Html parser is slowing the application down.Webpage and very large. I have tried that option and it is not efficient. It literally hangs once I call the html parser. That is why I opted for this option. I am basically crawling cart pages to get product names and setState. – tksilicon Feb 29 '20 at 18:08
  • If your app “literally hangs once I call the html parser” you are using it wrong. I have been using HTML parsers for years and find their performance superior to Regexes. – Dour High Arch Mar 11 '20 at 19:21
  • Which html parser do you use for mobile app (react native) and can you load an Amazon product page and getelementbyClass efficiently? – tksilicon Mar 11 '20 at 19:54

1 Answers1

0

As someone has already mentioned, using regex for everything is a bad idea, especially if you're trying to parse HTML, there are better tools for that.

But to answer your question,

>[ \n]*?(.+)[ \n]*?<

This will match what you want, as long as the line doesn't have any line terminators.

Check out the demo

Chase
  • 5,315
  • 2
  • 15
  • 41