求C# Regex 的一个句子

来源:百度知道 编辑:UC知道 时间:2024/05/23 21:50:28
我的文件中全部是数字,我想用Regex 来读取出来,所有的数据;
但是有一些是用E科学方法记下来的,如
19.100000 19.100000 19.100000 19.100000
19.100000 19.100000 19.100000 19.100000
19.100000 19.100000 19.100000 19.100000
19.100000 5.480000E-01 5.480000E+01 5.480000E-01
5.480000E-01 5.480000E+01 5.480000E-01 5.480000E-01
我想把所有的数字都读出来,目前使用这样的方法:
string txtFileName = "results";
StreamReader sr = new StreamReader(txtFileName);
string text = sr.ReadToEnd();
sr.Close();

Regex r = new Regex(@"这里怎么写?");
Match m = r.Match(text);

while (m.Success)
{
szContents.Add(float.Parse(m.Value));
m = m.NextMatch();

}
因此
Regex r = new Regex(@"这里怎么写?"); ?怎么来填写?说白了,就是除了空白符号,其它的都没限制

string oldstr = this.TextBox1.Text.ToString();
Regex rgx = new Regex(@"(\s*(?<temp>\d+\.\d+)\s)|(\s*(?<temp>\d+\.\d+E.*?\d+?)\s)", RegexOptions.Compiled);

MatchCollection results = rgx.Matches(oldstr);
foreach (Match mat in results)
{
this.TextBox2.Text += mat.ToString().Trim() + "\n";
}
希望对您有点帮助.

"\w"

提供一点点
Regex("数字.数字[0,E[-,+]数字]");

Regex("^\d+\.\d*|\d+\.d*E-d+|\d+\.d*E+\d+$");
式子比较繁琐

(?<=\s)[^\s](?=\s)