Paul
Paul

Reputation: 119

Match text in parentheses only if followed by certain char

My test string: (MATCH) X (MATCH)[1] "(NO MATCH)" (NO MATCH)X (MATCH) X I want to match the text in the parentheses (with the parentheses), but only if the parentheses are followed by a whitespace or a [.

I currently have this regex, but it is greedy and i don't know how to make it lazy.

How do i make my regex expression lazy ?

Upvotes: 1

Views: 3336

Answers (1)

Sujith PS
Sujith PS

Reputation: 4864

You can use :

(\([^\)]*?\))(?=[\[\s])

DEMO

EXPLANATION :

enter image description here

Upvotes: 5

Related Questions