Recipe 49Testing a Pattern with the Positive Lookbehind

Task

Suppose your task is to extract questions from a standardized test and store them in a database. The info you’re looking for always comes after a numbering system like “Question #5:”, but you want to extract the question text without its numbering.

The sticky flag wouldn’t be effective in this case because the length of characters in the numbering system varies between questions. For instance, one question may begin with “Question #9,” while another question may start with “Question #10” (for more on the sticky flag, see Recipe 44, Searching from a Specific Index with the y Flag).

You need a solution that allows you to match questions preceded by a “Question #n” without including ...

Get Text Processing with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.