Home > Back-end >  Replace RegExp named captured group in Sublime Text & Visual Studio Code
Replace RegExp named captured group in Sublime Text & Visual Studio Code

Time:05-04

I would like to do the replacement of the named capture group in these two IDE, Sublime Text and Visual Studio Code. And, I actually succeed in using IntelliJ WebStorm.

An example corpus was:

Title: Hamlet
Genre: Tragedy
Playwright: Williams Shakespere

Title: Woyzeck
Genre: Tragedy
Playwright: Karl Georg Büchner

and I used the following RegEx to retrieve the playwright

Playwright: (?<playwright>.*)

and replace this with the following RegEx to wrap in an XML format for the further analysis

<playwright>${playwright}</playwright>

Both Sublime Text and Visual Studio Code failed with this outcome:

Title: Hamlet
Genre: Tragedy
<playwright>${playwright}</playwright>

Title: Woyzeck
Genre: Tragedy
<playwright>${playwright}</playwright>

While WebStorm delivered the right results

Does anyone know how to make it with these two IDEs?

CodePudding user response:

In SublimeText, the replacement pattern can contain named backreferences and should look like

<playwright>$ {playwright}</playwright>

In Visual Studio Code, named backreferences are not supported in the replacement patterns (the feature request did not collect enough community upvotes).

  • Related