Jorge
Jorge

Reputation: 695

Duplicate a named capturing group

Considering the string

aaa"bbb"

And the REGEX

(?<first>.+?(?="))"(?<first>.+?(?="))

We have the named capturing group

'first' => aaa
'second' => bbb

I want, as result a duplicated capturing group with the same value, like:

'first' => aaa
'duplicated' => aaa
'second' => bbb

Do you know how can we do this?

Upvotes: 2

Views: 1821

Answers (2)

ohaal
ohaal

Reputation: 5268

Just put a "duplicated" capture group inside the "first" capture group.

(?<first>(?<duplicated>.+?(?=")))"(?<second>.+?(?="))

Upvotes: 4

Andynedine
Andynedine

Reputation: 441

I don't understand you at all, but with this pattern you can get your values:

Expresion: ^([^\"]*)\"([^\"]*)\"$
String: aaaa"bbb"
Replace: $1__$1__$2
Result: aaaa__aaaa__bbb

More info, use

http://www.metriplica.com/es/recursos/expresiones-regulares

Upvotes: -1

Related Questions