-1

I'm having a trouble with blog posts excerpt..

I'm using Wordpress as headless CMS and it returns me post excerpt in specific format. It looks like <p>some text here [...]</p> and I'm trying to write one regular expression that will get rid of paragraphs and those brackets with dots in between.

I ended up with something like

excerpt.replace(/<p>|<\/p>/g, '') and it works with paragraphs but I can't find any solution to get rid of those three dots in one regular expression..

Is that possible at all?

  • https://stackoverflow.com/a/1732454 – adiga Jul 29 '20 at 08:31
  • @adiga the problem wasn't with html tags but with the dots :P – Wiktor Gała Jul 29 '20 at 08:40
  • It is not clear what you want to achive. Do you want to remove p tgas with those ellipsisi inside, or only th eellipssi itsel from p tags? – sçuçu Jul 29 '20 at 08:42
  • Don't forget to accept (tick check-mark next to the answer) your own answer (possible after a wait-period of 48 hours), so that your question stops showing up as unanswered in the searches. – Ivo Mori Jul 29 '20 at 09:26

1 Answers1

0

Ok - I didn't notice one thing xD

Wordpress returns […] instead of [...]..

Now everything works perfectly with something like

const parsedExcerpt = excerpt.replace(/<p>|<\/p>|\r?\n|\r|\[…]/g, '');