ファイルのすべての行をループしようとしており、「」を含む行ごとに、一致を行自体に置き換えようとしていますが、最後にも「」があります。
.NET/C# から次のような構文を使用しています。
Regex re = new Regex("/\"/"); // without escaping would be /"/
re.Replace(" someAttr=\"some text here", "$0\"");
Try the following:
Regex re = new Regex("\".*");
re.Replace(" someAttr=\"some text here", "$&\"");
First, you need to lose the slashes surrounding your regex.
According to this .NET regex reference page, $&
is the reference to the entire match, not $0
.
Also with your current method, you would just be replacing one double-quote with two consecutive double-quotes. Since you want to add the new double-quote to the end of the line you need to make your regex match to the end of the line, which is what the .*
does.
Example: http://ideone.com/K5A7D
line="some text.d.sd..dsd.";
Regex r=new Regex("\".*");
r.Replace(line,"$0\"");
これもうまくいくはずです:
string line = "This is a string";
Regex re = new Regex("[\"].*");
re.Replace(line,"$0\"");