我要对一行歌词进行分析,比如: [00:00.40][00:03.59][00:18.37]I Was Born To Love You 我需要利用正则匹配分析后得到 var arr=['00:00.40','00:03.59','00:18.37'] 不会正则,悲剧了,求指教。
var reg = /[\d]{2}:[\d]{2}.[\d]{2}/g; var arr = '[00:00.40][00:03.59][00:18.37]I Was Born To Love You'; var result = reg.exec(arr);######Ruby: ' [00:00.40][00:03.59][00:18.37]I Was Born To Love You' .scan /(?![)\d{2}:\d{2}.\d{2}(?=])/ Javascript: "[00:00.40][00:03.59][00:18.37]I Was Born To Love You'".match(/(?![)\d{2}:\d{2}.\d{2}(?=])/g)######恩,十分感谢。###### <script> var r=/[(\d\d:\d\d.\d\d)]/ig; r=/\d\d:\d\d.\d\d/ig; //r=/w/ig var s="[00:00.40][00:03.59][00:18.37]I Was Born To Love You"; //alert(s); var a= s.match(r); alert(a); </script> 严谨的写法是第一个,但是js不支持零宽断言,所以,你只好祈祷歌词里面没有这个格式的字符了。 ######谢谢,受教了。花点时间去研究下正则,不会很多事情做不了。######写错了,最后应该是var result = arr.match(reg);###### python的:
import re
a = '[00:00.40][00:03.59][00:18.37]I Was Born To Love You'
b = re.findall(r'\d\d\W\d\d\W\d\d',a)
print b
######
import re print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')######
import re print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
import re print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
var arr = '[00:00.40][00:03.59][00:18.37]I Was Born To Love You'.match(/[\d:.]+/g);######嗯,学习了。######
import re print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。