-1

I wanted to write a JavaScript regex for the following text:

If you’re curious about this, it’s a garbled quotation from Cicero’s De Finibus Bonorum et Malorum (On the Ends of Good and Bad), book 1, paragraph 32, which reads, “Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit,” meaning, “There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain.” The book was popular during the Renaissance, when the passage was used in a book of type samples for that wonderful new technology, printing.

If the regex matches Bonorum, it should capture all the content after the Bonorum text until passage.

I'm trying with (issue\s+date)(.*?)excluding, but it is not working

Thank You

Booboo
  • 38,656
  • 3
  • 37
  • 60

1 Answers1

0

See Regex Demo

let s =  "If you’re curious about this, it’s a garbled quotation from Cicero’s De Finibus Bonorum et Malorum (On the Ends of Good and Bad), book 1, paragraph 32, which reads, “Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit,” meaning, “There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain.” The book was popular during the Renaissance, when the passage was used in a book of type samples for that wonderful new technology, printing.";
let regex = /(?<=Bonorum ).*?passage/;
let result = regex.exec(s);
if (result) {
    console.log(result[0])
}

Or you could use /(?<=\bBonorum ).*?\bpassage\b/ to ensure Bonorum and passage are on word boundaries, if that is a requirement.

Or use /(?<=\bBonorum ).*?(?=\bpassage\b)/ if you do not want to include the word passage (not entirely clear in the question).

Booboo
  • 38,656
  • 3
  • 37
  • 60