看看这个贴子的例子: http://topic.csdn.net/u/20090913/20/13145e3c-32fb-49da-978c-0b06244667ac.htmlusing System; using System.IO; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { static void Main() { using (StreamReader sr = new StreamReader("abc.txt", Encoding.GetEncoding("GB18030"))) { string text = sr.ReadToEnd(); // Console.WriteLine(text); List<string> list = new List<string>(); foreach (Match m in Regex.Matches(text, @"(?<=\*).{2}-\d+(?=\*)")) { list.Add(m.Value); } string[] array = list.ToArray(); // 这就是你要的车牌号数组。
看看这个贴子的例子: http://topic.csdn.net/u/20090913/20/13145e3c-32fb-49da-978c-0b06244667ac.htmlusing System; using System.IO; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { static void Main() { using (StreamReader sr = new StreamReader("abc.txt", Encoding.GetEncoding("GB18030"))) { string text = sr.ReadToEnd(); // Console.WriteLine(text); List<string> list = new List<string>(); foreach (Match m in Regex.Matches(text, @"(?<=\*).{2}-\d+(?=\*)")) { list.Add(m.Value); } string[] array = list.ToArray(); // 这就是你要的车牌号数组。
百度下就OK了
http://topic.csdn.net/u/20090913/20/13145e3c-32fb-49da-978c-0b06244667ac.htmlusing System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions; class Program
{
static void Main()
{
using (StreamReader sr = new StreamReader("abc.txt", Encoding.GetEncoding("GB18030")))
{
string text = sr.ReadToEnd();
// Console.WriteLine(text);
List<string> list = new List<string>();
foreach (Match m in Regex.Matches(text, @"(?<=\*).{2}-\d+(?=\*)"))
{
list.Add(m.Value);
}
string[] array = list.ToArray(); // 这就是你要的车牌号数组。
foreach (string s in array)
Console.WriteLine(s);
}
}
}
其中正则表达式:
@"(?<=\*).{2}-\d+(?=\*)"
(?<=\*) 表示左边是 * 字符,正则式中 * 有特殊含义,需要用 \ 转义,
.{2} 匹配任意字符正好2次,
- 匹配 - 字符本身,
\d+ 匹配数字字符一次或多次,
(?=\*) 表示右边是 * 字符。
http://topic.csdn.net/u/20090913/20/13145e3c-32fb-49da-978c-0b06244667ac.htmlusing System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions; class Program
{
static void Main()
{
using (StreamReader sr = new StreamReader("abc.txt", Encoding.GetEncoding("GB18030")))
{
string text = sr.ReadToEnd();
// Console.WriteLine(text);
List<string> list = new List<string>();
foreach (Match m in Regex.Matches(text, @"(?<=\*).{2}-\d+(?=\*)"))
{
list.Add(m.Value);
}
string[] array = list.ToArray(); // 这就是你要的车牌号数组。
foreach (string s in array)
Console.WriteLine(s);
}
}
}
其中正则表达式:
@"(?<=\*).{2}-\d+(?=\*)"
(?<=\*) 表示左边是 * 字符,正则式中 * 有特殊含义,需要用 \ 转义,
.{2} 匹配任意字符正好2次,
- 匹配 - 字符本身,
\d+ 匹配数字字符一次或多次,
(?=\*) 表示右边是 * 字符。
http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm
另外,推荐一本书: