Home > Archive > Visual Studio > February 2006 > Using RegExp with Submatches in VS-Replace-dialog
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using RegExp with Submatches in VS-Replace-dialog
|
|
| Alexander Mueller 2006-02-13, 7:01 pm |
| Hi @all
is it possible to use submatches in the search & replace dialog of visual studio
2005? I want to replace uniform patterns of VB-6-code that deal with different
variable-names and different literals but have fully identical same structure,
example:
old VB-Code:
If (Left(strName, Len("SAB3_4_CREDIT")) = "SAB3_4_CREDIT" Then
If (Left(strLoan, Len("RNT_7_CREDIT")) = "RNT_7_CREDIT" Then
i want to change it to
If strName.StartsWith ("SAB3_4_CREDIT") Then
If strLoan.StartsWith ("RNT_7_CREDIT") Then
I know RegExp from Jscript 5.6 (WSH) and a pattern to find
this Left-Len-construct and building submatches for the varaible
and the literal goes like this:
var r = /\(Left\((\w+), Len\(("[^"]+")\)\) = "[^"]+" Then/;
the replace-expression for JScript is:
$1.StartsWith($2) Then
VStudio seesm to have the same syntax for finding-patterns.
But it seems to have a different syntax to denote submatches
inside the replace-expression, if any.
Is there support for submatches in the replace-expression, at all?
Thanks for your help,
Alex
| |
| Alexander Mueller 2006-02-14, 3:59 am |
| Alexander Mueller schrieb:
> I know RegExp from Jscript 5.6 (WSH) and a pattern to find
> this Left-Len-construct and building submatches for the varaible
> and the literal goes like this:
>
> var r = /\(Left\((\w+), Len\(("[^"]+")\)\) = "[^"]+" Then/;
>
> the replace-expression for JScript is:
>
> $1.StartsWith($2) Then
>
> VStudio seesm to have the same syntax for finding-patterns.
> But it seems to have a different syntax to denote submatches
> inside the replace-expression, if any.
> Is there support for submatches in the replace-expression, at all?
Thanks to Herfried I found that VStudio-online help uses the term
'tagged expressions' for submatches, curly brackets for building them
and \n for referencing them in a replace-pattern.
So changing all occurences
If Left(<varname>, Len("<string-literal>")) = "<string-literal>" Then
to
<varname>.StartsWith("<string-literal>") Then
can be by achieved by setting
search to: Left\({:a+}, Len\({"[^"]+"}\)\) = "[^"]+" Then
replace to: \1.StartsWith(\2)
and clicking Replace All.
just in case anybody else wants to migrate his old code to NET.
Mfg,
Alex
|
|
|
|
|