简体   繁体   中英

C# razor regex replace some occurrences of dot with 1/6 emspace

in a string whenever the following occurs

~A.~ ( tilde, then any single upper case letter, then dot, then tilde)

I want to replace the 'dot' with a 1/6 em space. I have tried several things including this but its not doing what I want

text = Regex.Replace(text, @"/(~)([A-Z])(.~)/g", "$1$2&8198;~");

Just use

~([A-Z])\.~

And replace this with

~$1\u2006~

The unicode spaces can be found here , the appropriate replacement is sth. like \ሴ567889 .


As a whole snippet:

 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 = "~([AZ])\\\\.~"; string replacement = "~$1\ ~"; Regex rx = new Regex(pattern); string result = rx.Replace(txt, replacement); Console.WriteLine("Replacement String: {0}", result); } } 

See a demo on ideone.com .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM