C# C razor regex用1/6 emspace替换一些出现的点
在字符串中,每当发生以下情况时 ~A.~tilde,然后是任何一个大写字母,然后是dot,然后是tilde 我想用1/6 em的空格替换“点”。 我已经尝试了很多东西,包括这个,但它没有做我想要的C# C razor regex用1/6 emspace替换一些出现的点,c#,regex,C#,Regex,在字符串中,每当发生以下情况时 ~A.~tilde,然后是任何一个大写字母,然后是dot,然后是tilde 我想用1/6 em的空格替换“点”。 我已经尝试了很多东西,包括这个,但它没有做我想要的 text = Regex.Replace(text, @"/(~)([A-Z])(.~)/g", "$1$2&8198;~"); 只用 ~([A-Z])\.~ 并将其替换为 ~$1\u2006~ 可以找到unicode空格,相应的替换为\u1234567889。 作为一个整体片段: us
text = Regex.Replace(text, @"/(~)([A-Z])(.~)/g", "$1$2&8198;~");
只用
~([A-Z])\.~
并将其替换为
~$1\u2006~
可以找到unicode空格,相应的替换为\u1234567889。
作为一个整体片段:
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string txt = "~A.~ ( tilde, then any single upper case letter, then dot, then tilde)";
string pattern = "~([A-Z])\\.~";
string replacement = "~$1\u2006~";
Regex rx = new Regex(pattern);
string result = rx.Replace(txt, replacement);
Console.WriteLine("Replacement String: {0}", result);
}
}
看 谢谢,我刚刚不得不双倍逃离这个点。