求一句正则语句

changechange 2012-04-27 09:13:15
从字符串

xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 wlsr665

中找出 1111111111 和 2222222222 这两个都是数字的字符串。
规则是 这两个字符串都是10位的数字,数字的内容会变的,且一定要以 空格上海黄丽快递公司(运营部) 开头+位数不确定的数字(比如上面的85), 空格wlsr 结尾


再举几个例子

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 wlsr665


...全文
3425 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2012-04-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
C# code


foreach(Match m in Regex.Matches(html,@"(?i)\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr"))
{
foreach(Capture c in m.Groups[1].Captures)
{
Console.Wr……
[/Quote]


.NET 才支持 Captures , VBS 里面没有的。
你的选择H 2012-04-27
  • 打赏
  • 举报
回复
string str = @"asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 3333333333 wlsr665
";
List<string[]> list = new List<string[]>();
MatchCollection collec = Regex.Matches(str, @"(?<= 上海黄丽快递公司\(运营部\) \d+)( \d{10}){1,}(?= wlsr)");
foreach (Match item in collec)
{
string[] strs = Regex.Split(item.Value, " ");
list.Add(strs);
}
q107770540 2012-04-27
  • 打赏
  • 举报
回复

//不会vbscript,给你写个C# 版本的,思路参考吧
void Main()
{
var html = @"xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 wlsr665

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 wlsr665

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 3333333333 wlsr665

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 3333333333 4444444444 wlsr665";
foreach(Match m in Regex.Matches(html,@"(?i)\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr"))
{
foreach(Capture c in m.Groups[1].Captures)
{
Console.Write("{0}\t",c.Value);
}
Console.WriteLine();
}

/*
1111111111 2222222222
1111111111 2222222222
1111111111 2222222222
1111111111 2222222222
1111111111 2222222222 3333333333
1111111111 2222222222
1111111111 2222222222 3333333333 4444444444
*/
}
q107770540 2012-04-27
  • 打赏
  • 举报
回复
\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr
mingfish2 2012-04-27
  • 打赏
  • 举报
回复
上海黄丽快递公司(运营部)\s\d{1,2}\s(\d{10}\s\d{10})\swlsr
括号中的就是结果了
changechange 2012-04-27
  • 打赏
  • 举报
回复
再举几个例子

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 3333333333 wlsr665

asdfak asad392393 sdallz9303923 上海黄丽快递公司(运营部) 1 1111111111 2222222222 wlsr0
dkk3i23j 855155 iki3f xkdkamsdfk askdfaksdlf asdkfao 上海黄丽快递公司(运营部) 85 1111111111 2222222222 3333333333 4444444444 wlsr665

注意,10位数字有可能是一组,也有可能是多组的。
q107770540 2012-04-27
  • 打赏
  • 举报
回复

foreach(Match m in Regex.Matches(html,@"(?i)\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr"))
{
foreach(Capture c in m.Groups[1].Captures)
{
Console.Write("{0}\t",c.Value);
}
Console.WriteLine();
}




For Each m In varMatch
'VBScript内的正则也应该有Capture 这个吧。。。
For Each cp in m.Groups(1).Captures
Debug.Print cp.Value
Next
'Debug.Print m.Value, m.FirstIndex
'Instr3 = Instr3 & m.Value
Debug.Print m.SubMatches(0)
Next
changechange 2012-04-27
  • 打赏
  • 举报
回复
Function Instr3(ByVal regExPattern As String, ByVal s As String) As String
Dim reg As New RegExp
Dim varMatch As Variant
Dim m As Variant

reg.Pattern = regExPattern
reg.IgnoreCase = True
reg.Global = False
Set varMatch = reg.Execute(s)
For Each m In varMatch
'Debug.Print m.Value, m.FirstIndex
'Instr3 = Instr3 & m.Value
Debug.Print m.SubMatches(0), m.Value
Next

End Function

Function dddddd()
'Debug.Print Instr3("\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr", "a 上海黄丽快递公司(运营部) 8 1111111111 2222222222 3333333333 wlsr")
Debug.Print Instr3("上海黄丽快递公司(运营部)\s\d{1,2}\s(\d{10}\s\d{10})\swlsr", "a 上海黄丽快递公司(运营部) 8 1111111111 2222222222 3333333333 wlsr")

End Function


则没有结果
changechange 2012-04-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr
[/Quote]


Function Instr3(ByVal regExPattern As String, ByVal s As String) As String
Dim reg As New RegExp
Dim varMatch As Variant
Dim m As Variant

reg.Pattern = regExPattern
reg.IgnoreCase = True
reg.Global = True
Set varMatch = reg.Execute(s)
For Each m In varMatch
'Debug.Print m.Value, m.FirstIndex
'Instr3 = Instr3 & m.Value
Debug.Print m.SubMatches(0)
Next

End Function

Function dddddd()
Debug.Print Instr3("\s*上海黄丽快递公司\(运营部\)\s*\d+\s*(\d{10}\s*)+wlsr", "a 上海黄丽快递公司(运营部) 8 1111111111 2222222222 3333333333 wlsr")
End Function

只返回 3333333333,实际上我要返回 1111111111 2222222222 3333333333 3组字符串

4,007

社区成员

发帖
与我相关
我的任务
社区描述
它是一种微软环境下的轻量级的解释型语言,它使用COM组件、WMI、WSH、ADSI访问系统中的元素,对系统进行管理。
社区管理员
  • vbScript社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧