Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex - how to avoid a certain group?

Tags:

regex

I need to match a right bracket followed by a quote: )"

like the last two characters in this string:

He said "Free Willi (song)"

I use the following regex which indeed match them:

(?:\))(")

My problem has to do with the grouping: this regex results in two groups:

Group 1: )"

Group 2: "

I would like to avoid the first group and have only one group that includes the double quotes (because of some generic code that uses the first group only).

Is there a way to avoid the first group?

I thought I did it by using the ?: on the left hand side of the expression, but apparently I didn't.

like image 438
Carmel Baumel-Ezra Avatar asked Dec 06 '25 23:12

Carmel Baumel-Ezra


1 Answers

You could use positive lookbehind,

(?<=\))(\")

DEMO

It searches for the " just after ). If it founds any, then the corresponding double quotes would be matched.

like image 151
Avinash Raj Avatar answered Dec 09 '25 17:12

Avinash Raj