Having issue getting the inner Text of a tag with regex.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having issue getting the inner Text of a tag with regex..

I am trying to get the innertext with regex but it also selects text within tag like class heading etc.. i just want to get the "Take your business strategy to the next level and automatize your marketing tasks to save time for product development." <p class="p-heading">Take your business strategy to the next level and automatize your marketing tasks to save time for product development.</p>

20th Jun 2020, 11:48 AM
Hassan Raza
Hassan Raza - avatar
2 Answers
+ 1
Basic way would be this: let text = '<p class="p-heading">Take your business strategy to the next level and automatize your marketing tasks to save time for product development.</p>'; let string = text.match(/>(.*?)</)[1] console.log(string) // Take your business strategy to the next level and automatize your marketing tasks to save time for product development. If you have a more complicated set-up (with nested element for example), it would require more work.
20th Jun 2020, 6:10 PM
Russ
Russ - avatar
+ 3
If you can link that part of code section where you are trying to get text using regex then only someone might know why it is so ,and can provide you any help
20th Jun 2020, 12:08 PM
Abhay
Abhay - avatar