作者check (check)
看板C_Sharp
标题[问题] regex与substring的问题
时间Thu Apr 21 00:50:26 2011
各位高手你们好 小弟看了老半天对Regex还是没什麽头绪
也不敢乱猜到底正确答案是什麽 请帮我解惑
我的程式码如下
System.Text.RegularExpressions.
Regex regex =
new
System.Text.RegularExpressions.
Regex(
@"\[.*\]");
.*代表的是零个或多个任意字元对吗?
那中括号前方的\是什麽用途?前面已有@ 应该不是逸出字元?
System.Text.RegularExpressions.
Match match = regex.Match(line);
this.expectations.Add(match.Value.Substring(2,match.Value.Length-6));
其中line是从文件读入一列字串
我想请问(2,match.Value.Length-6) 是什麽意思?
我尝试更改-6变成其他数字,好像都没影响到结果?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.27.121
※ 编辑: check 来自: 140.112.27.121 (04/21 00:51)
1F:推 bdvstg:是逸出字元呀傻孩子 不过不是C#的(已被@忽略) 是Regex的 04/21 11:19
2F:→ check:原来如此 谢谢楼上 (跪) 04/21 14:27