开发者社区> 问答> 正文

这个正则表达式怎么写?:报错

我要对一行歌词进行分析,比如: [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'] 不会正则,悲剧了,求指教。

展开
收起
kun坤 2020-06-09 15:26:18 529 0
1 条回答
写回答
取消 提交回答
  • 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

    ######

    引用来自“libinhui”的答案

    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
    [\d:.]+ 就够了
    import re
    print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
    ######

    引用来自“redraiment”的答案

    引用来自“libinhui”的答案

    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
    [\d:.]+ 就够了
    import re
    print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
    谢谢了。不过我用的javascript, ######

    引用来自“高老庄壮猪”的答案

    引用来自“redraiment”的答案

    引用来自“libinhui”的答案

    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
    [\d:.]+ 就够了
    import re
    print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
    谢谢了。不过我用的javascript,
    嗯,看到 var arr... 已经猜到了。JS 也是一样的:
    var arr = '[00:00.40][00:03.59][00:18.37]I Was Born To Love You'.match(/[\d:.]+/g);
    ######嗯,学习了。######

    引用来自“redraiment”的答案

    引用来自“libinhui”的答案

    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
    [\d:.]+ 就够了
    import re
    print re.findall(r'[\d:.]+', '[00:00.40][00:03.59][00:18.37]I Was Born To Love You')
    嗯,学习了。 ######谢谢楼上几位的热心解答。
    2020-06-09 19:13:55
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载