Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正则表达式提取其他字符之间的字符_C#_.net_Regex - Fatal编程技术网

C# 正则表达式提取其他字符之间的字符

C# 正则表达式提取其他字符之间的字符,c#,.net,regex,C#,.net,Regex,我有一个字符串,它是/{characters}\n 我需要一个正则表达式来提取/和\n之间的字符正则表达式非常好,但是为什么不使用子字符串呢 string input = "//{characters}\n"; string result = input.Split('\n')[0].Substring(2); 或 这应该起作用: string s1 = "//{characters}\n"; string final = (s1.Replace("//", "").Replace("\n

我有一个字符串,它是
/{characters}\n


我需要一个正则表达式来提取
/
\n
之间的字符正则表达式非常好,但是为什么不使用子字符串呢

string input = "//{characters}\n";
string result = input.Split('\n')[0].Substring(2);

这应该起作用:

string s1 =  "//{characters}\n";
string final =  (s1.Replace("//", "").Replace("\n", ""));
使用正则表达式:

Regex g;
Match m;
g = new Regex("//(.*)\n");  // if you have just alphabet characters replace .* with \w*
m = g.Match(input);
if (m.Success == true)
    output = m.Groups[1].Value;

@BaliC Regex.Match(number,@“\/\w+\\n”).Groups[1]。value我已使用//\n1;2.预期产量为;在//和\n之间。但找不到匹配项。再次,如果您确定输入以//开头,则应使用“^/(.*)”\n。请记住,正则表达式将匹配输入字符串“//one\ntwo\n”,比如“one\ntwo”Hello Mist RegEx=new RegEx(@“([)?(*)(*))?”;match=regex.match(分隔符);(match.Success){delimiters.Add(match.Groups[1].Value);match=match.NextMatch();}试图将字符从[*][&][%]提取到包含*,&,%的列表中。输入也可以是*&%,并期望相同的输出。你能帮我做同样的事情吗?是的,我们可以做字符串运算,但这是我最后的选择。
Regex g;
Match m;
g = new Regex("//(.*)\n");  // if you have just alphabet characters replace .* with \w*
m = g.Match(input);
if (m.Success == true)
    output = m.Groups[1].Value;