Using VS2010’s find dialog, I’m using the following regex: (?'outer'^div\#.+) input$.
I’m trying to create a named group of “outer” with the contents div#someId from div#someId input (in this case where someId matches .+)
However, Visual Studio is presenting the dialog: Grouped expression is missing ')'.
However, the ) is there after the +. What am I escaping or failing to escape?
EDIT:
I don’t necessarily need to used named groupings, I just need to be able to use div#someId in the replace to add another selector.
It appears that Visual Studio’s find and replace uses braces
{ }and not parentheses( )for backreferences and named references.Since someone may find this trying to use backreferences/named grouping in a Find and Replace in Visual Studio, here’s an example of using them:
To replace
with
Find:
{^div\#.+ }inputand replace with:\0,\n\1textareaIt will put
div#someId(with the space, which matches^div\#.+into the first backreference.Building the replace string with a backreference:
The replace will then replace the whole string :
\0then a comma:
,then a new line:
\nthen the first group:
\1then the given text:
textareaAltogether makes the replace string
\0,\n\1textareaUpdate: Based on this MSDN question in VS2012 backreferences are accessed using
$nrather than\n, so the replace string would be:$0,\n$1textarea