首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
V2EX 提问指南
广告
V2EX
›
问与答
javascript 的正则表达式 不支持优先取分组里面的值 有什么解决办法吗
upufo
·
2016-03-21 07:36:46 +08:00
· 1400 次点击
这是一个创建于 3128 天前的主题,其中的信息可能已经有所发展或是发生改变。
正则: hello src=(.+) yes
内容: hhsdj dskj hello src=value yes
上面的正则只能匹配出 [ hello src=value yes ]
如果我想要取等号后面的 value 这个字符串 应该怎么写呢?
src
正则
value
yes
2 条回复
•
2016-03-21 09:07:30 +08:00
1
TTry
2016-03-21 08:03:42 +08:00
1
str.match(regexp)[1]
2
ppgs8903
2016-03-21 09:07:30 +08:00
1
var re = /hello src=(.+) yes/;
var str = "hhsdj dskj hello src=value yes";
re.exec(str);
alert(RegExp.$1);
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
1080 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms ·
UTC 18:19
·
PVG 02:19
·
LAX 11:19
·
JFK 14:19
Developed with
CodeLauncher
♥ Do have faith in what you're doing.