Carmel Baumel-Ezra
Carmel Baumel-Ezra

Reputation: 305

Regex - how to avoid a certain group?

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.

Upvotes: 3

Views: 68

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

You could use positive lookbehind,

(?<=\))(\")

DEMO

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

Upvotes: 3

Related Questions