English 中文(简体)
填补空缺,随后是数位数
原标题:Regex replacement capture followed by digit
  • 时间:2010-08-12 10:59:34
  •  标签:
  • .net
  • regex

我正试图找一个雷克斯替代机构,努力更新我的议会信息文件。

Regex.Replace(
    contents, 
    @"([assembly: Assembly(File)?Version("").*("")])", 
    "$1" + version + "$3"
);

问题在于,<代码>,<> 是1.5.3.0>,因此,在评价替换时,见,11.5.3.0美元“,并大概看第十一个被捕获群体,因为它是:

$11.5.3.0")]

如果在<代码>1美元后保留一个空间,则该空间可进行罚款。 在不实际插入字面的情况下,我需要怎么做才能逃脱第二位数?

最佳回答

使用<代码>${1}而不是$1。 http://msdn.microsoft.com/en-us/library/bs2twtah.aspx” rel=“noretinger” 捕获组<<>代码>(?<name>)。

The s snippet to show (,另见关于ideone.com:

Console.WriteLine(Regex.Replace("abc", "(.)", "$11"));        // $11$11$11
Console.WriteLine(Regex.Replace("abc", "(.)", "${1}1"));      // a1b1c1
Console.WriteLine(Regex.Replace("abc", "(?<x>.)", "${x}1"));  // a1b1c1

这种行为明确记录在案:

Regular Expression Language Elements - Substitutions

Substituting a Numbered Group

<代码> 序号 语文部分包括最后一项与<代码>/代码>对应的编号。 替换舱位中的捕获组, 编号是捕获组的索引。

如果<代码>>>>>没有具体规定固定表述方式界定的有效捕获组,$被解释为literal nature series,用以取代每一配方。

Substituting a Named Group

<代码> 姓名><>/代码> 语文要素替换了与<代码> 姓名>/代码>格格言对应的最后一个次体,其中<代码> 姓名/代码>是指由<代码>界定的代号组的名称(>?< 姓名和gt; 语文要素。

如果<代码> 姓名/代码>没有具体说明固定表述方式界定的有效名称捕获组,${name><>/code>被解释为literal nature series,用以取代每一配方。

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...