i am having trouble with regex for dectecting all characters between the keyword "QUESTION"
I want to select all Question but i couldn't select a Question already present in the first match when i use this regex (the result is bold):
(Question |QUESTION |QCM )(.)*?(Question |QUESTION |QCM )
QUESTION N°%6 : A PROPOS DE LA MYOLOGIE DE L EXTREMITE CEPHALIQUE : C. Le nerf facial se termine dans la loge submandibulaire. | D. Tous les muscles peauciers sont innerves par le nerf facial. . risa baile E. La contraction du muscle platysma entraine un abaissement de la lévre inférieure. QUESTION N°7 : A PROPOS DE LA MYOLOGIE DE L'EXTREMITE CEPHALIQUE : Re ear al 30 A. Le muscle buccinateur est innervé par le nerf mandibulaire. | oe ee B. La contraction du muscle élévateur nasolabial entraine une constriction de la narine. QUESTION N°8 : A PROPOS DE L'ARTICULATION TEMPOROMANDIBULAIRE : A. Les articulations temporo-mandibulaires sont de type sphéroide. mandibulaire. Question
i need to match with all Questions. thank you
CodePudding user response:
You could write the pattern with an assertion and the capture group around the whole matching part.
\b(Question|QUESTION|QCM)\s (.*?)(?=\s (?:Question|QUESTION|QCM)\s|$)
Explanation
\b
A word boundary(Question|QUESTION|QCM)
Capture any of the alternatives in group 1\s
Match 1 word characters(.*?)
Capture any character in group 2, as few as possible(?=\s (?:Question|QUESTION|QCM)\s|$)
Assert that to the right is either a new variation of question between whitespace chars, or the the end of the string