如何在字符串中提取数字

LUCKY-JUN 2006-05-19 11:35:15
有如下的字符串:
[5.19][软件更新][DGREE-R/411M][简体中文]
[5.19][软件更新][Flash/31MB][英文]
[5.19][软件更新][DGREE-R/1.5G][中文]

我想提取其中的:411M、31MB、1.5G
怎么写正则表达式呢?

...全文
148 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2006-05-19
  • 打赏
  • 举报
回复
(\/)(\d+([.]\d+)?)\w+
LUCKY-JUN 2006-05-19
  • 打赏
  • 举报
回复
字符串是这样的:
[WERFSDF/500MB]
[中文\4.5G]
[E文/550.9MB]
[EEG3FFE/3.9GB]
[400M]
[500MB]
[6G]
[7.1GB]

这样的呢?要个通用的,并且要带单位M、MB、G、GB
wanghui0380 2006-05-19
  • 打赏
  • 举报
回复
sorry!刚刚的正则写错了一点点,忘了判断整数了,下面这个是正确的

<%
str ="[5.19][软件更新][DGREE-R/1.5G][中文]"
pattern = "(\/)(\d+([.]\d+)?)\w"
set regex = new regexp
regEx.Pattern = pattern
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
For Each Match in Matches
response.write Replace(Match.Value,"/","")
Next


%>
wanghui0380 2006-05-19
  • 打赏
  • 举报
回复
<%
str ="[5.19][软件更新][DGREE-R/1.5G][中文]"
pattern = "(\/)(\d+[.]\d+)\w"
set regex = new regexp
regEx.Pattern = pattern
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
For Each Match in Matches
response.write Replace(Match.Value,"/","")
Next


%>
iasky 2006-05-19
  • 打赏
  • 举报
回复
正则

'|\[软件更新\]\[.*?/([\dA-Z]+)\]\[.*?\]|'
LUCKY-JUN 2006-05-19
  • 打赏
  • 举报
回复
在线等待22222
onlytiancai 2006-05-19
  • 打赏
  • 举报
回复
wanghui0380 2006-05-19
  • 打赏
  • 举报
回复
((\/)|(\\))?(\d+([.]\d+)?)\w{2,3}

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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