找回密码
 加入
搜索
查看: 1294|回复: 4

[AU3基础] 求两三个转换酷狗LRC歌词的正则表达式

[复制链接]
发表于 2020-9-9 19:48:44 | 显示全部楼层 |阅读模式
歌词样板为:
[ti:歌名]
[offset:-1000]
[:]增强版卡啦OK式LRC歌词转换成LRC简装版格式的正则是?

[00:02]歌手
[00:04.10]歌名
[00:06.10]专辑名[00:08.10]
[00:10:100]卡啦OK式歌词
[00:20.10]卡[00:21.10]啦[00:22.10]OK[00:23.10]式[00:24.10]歌[00:25.10]词[00:28.10]
[00:30.10][00:40.10][01:10.10]卡啦OK式歌词
[00:50.10][00:55.10]格式[错误][[00:57.10]]的歌词
[01:05.10]卡啦[:[01:05.10]]OK[[01:05.10]:]式歌词
[123:59.74]卡啦OK式歌词[123:10][124:10]
[格式]]错误[00:60.75]的[歌词]
转换成这样:
[ti:歌名]
[offset:-1000]
[:]增强版卡啦OK式LRC歌词转换成LRC简装版格式的正则是?

[00:02]歌手
[00:04.10]歌名
[00:06.10]专辑名
[00:08.10].
[00:10:100]卡啦OK式歌词
[00:20.10]卡啦OK式歌词
[00:28.10].
[00:30.10][00:40.10][01:05.10]卡啦OK式歌词
[00:50.10][00:55.10]格式[错误][]的歌词  (匹配成这样也可 格式[错误]]的歌词)
[01:05.10]卡啦]OK[:]式歌词   (匹配成这两也可 卡啦]OK:]式歌词、卡啦[:]OK[:]式歌词)
[123:59.74]卡啦OK式歌词
[124:10].
[格式]]错误的[歌词]
标签规则:[0或多个字符:0或多个字符]即[:]中间有:号。像这样[:][0:0][0:][:0]为4个标签[][0]这两个不是标签。

求正则一:行尾最后一个标签前加换行和标签后加.或空格。实在麻烦的话,标签后不加字符也可。
求正则二:保留行首的一个或多个标签,删除行中的其它标签。
求正则三:是否可以一个正则做到上面两步。

发表于 2020-9-10 08:38:51 | 显示全部楼层
LRC 歌词没有卡拉OK的效果,如果楼主有兴趣,可以学习 KSC 歌词以及 AAS 字幕制作。
 楼主| 发表于 2020-9-10 22:12:26 | 显示全部楼层
a版的贴呢。。。呼叫A大大再看看为了搞明白a版那正则搞了个测试代码,最后还是没明白。
^(.+)、替换字符串中的\1、\2、\0是什么意思啊?
如果不只是数字,其它字符也算标签的正则是什么啊
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $sSource = _
                '[ti:歌名]' & @CRLF & _
                '[offset:-1000]' & @CRLF & _
                '[:]增强版卡啦OK式LRC歌词转换成LRC简装版格式的正则是?' & @CRLF & @CRLF & _
                '[00:02]歌手' & @CRLF & _
                '[00:04.10]歌名' & @CRLF & _
                '[00:06.10]专辑名[00:08.10] ' & @CRLF & _
                '[00:10:100]卡啦OK式歌词' & @CRLF & _
                '[00:20.10]卡[00:21.10]啦[00:22.10]OK[00:23.10]式[00:24.10]歌[00:25.10]词[00:28.10]' & @CRLF & _
                '[00:30.10][00:40.10][01:10.10]卡啦OK式歌词' & @CRLF & _
                '[00:50.10][00:55.10]格式[错误][[00:57.10]]的歌词' & @CRLF & _
                '[01:05.10]卡啦[:[01:05.10]]OK[[01:05.10]:]式歌词' & @CRLF & _
                '[123:59.74]卡啦OK式歌词[123:10][124:10]' & @CRLF & _
                '[格式]]错误[00:60.75]的[歌词]' & @CRLF & _
                '[格:式]' & @TAB & '[错:误][00:60.75]的[歌:词]'
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("增强版卡啦OK式LRC歌词转换成LRC简装版格式", 1025, 704, 423, 165, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_GROUP, $WS_TABSTOP))
$Group1 = GUICtrlCreateGroup("原始歌词内容", 10, 10, 535, 300)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Edit1 = GUICtrlCreateEdit("", 15, 25, 525, 245)
GUICtrlSetData(-1, $sSource)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Button5 = GUICtrlCreateButton("第一次替换", 140, 275, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Button6 = GUICtrlCreateButton("第二次替换", 225, 275, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Button7 = GUICtrlCreateButton("第三次替换", 310, 275, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Button8 = GUICtrlCreateButton("第四次替换", 395, 275, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Label2 = GUICtrlCreateLabel("分解步骤", 20, 280, 52, 17)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("行尾最后标签换行结果", 10, 320, 535, 300)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit2 = GUICtrlCreateEdit("", 15, 335, 525, 245)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Button1 = GUICtrlCreateButton("行尾最后标签换行", 110, 585, 125, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "行尾最后标签换行")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("清理非行首标签结果", 555, 10, 460, 300)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
$Edit3 = GUICtrlCreateEdit("", 560, 25, 450, 245)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
$Button2 = GUICtrlCreateButton("清理非行首标签", 655, 275, 125, 25)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO + $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "清理非行首标签")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("换行和清理结果", 555, 320, 460, 300)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
$Edit4 = GUICtrlCreateEdit("", 560, 335, 450, 245)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT)
$Button3 = GUICtrlCreateButton("先换行再清理", 655, 585, 125, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "先行尾最后标签换行后再清理非行首标签")
$Button4 = GUICtrlCreateButton("一步清理", 800, 585, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "一步执行行尾最后标签换行和清理非行首标签")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("最终是下面这样用的,所以才要正则一、二、三。直观点做成上面界面测试。", 278, 628, 412, 17)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Checkbox1 = GUICtrlCreateCheckbox("行尾最后标签换行", 283, 653, 122, 17)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Button10 = GUICtrlCreateButton("批量清理", 408, 649, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $sSRERe
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1 ;行尾最后标签换行
                        Local $sEdit1 = GUICtrlRead($Edit1)
                        ;$sSRERe = StringRegExpReplace($sEdit1, "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\.")
                        $sSRERe = StringRegExpReplace($sEdit1, "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\2~音乐")
                        GUICtrlSetData($Edit2, $sSRERe)
                Case $Button2 ;清理非行首标签
                        Local $sEdit1 = GUICtrlRead($Edit1)
                        $sSRERe = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sEdit1, _
                                        "(?mi)^(?:\[[\d]*:[\d:.]*\])+", "\0" & @CRLF & @TAB), _
                                        "(?mi)([^\]\R])(?:\[[\d]*:[\d:.]*\])+", "\1"), _
                                        "(?mi)^((?:\[[\d]*:[\d:.]*\])+)\r\n\t", "\1")
                        GUICtrlSetData($Edit3, $sSRERe)
                Case $Button3 ;先换行再清理
                        Local $sEdit1 = GUICtrlRead($Edit1)
                        ;$sSRERe = StringRegExpReplace($sEdit1, "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\.")
                        $sSRERe = StringRegExpReplace($sEdit1, "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\2~音乐")
                        GUICtrlSetData($Edit2, $sSRERe)
                        Local $sEdit2 = GUICtrlRead($Edit2)
                        $sSRERe = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sEdit2, _
                                        "(?mi)^(?:\[[\d]*:[\d:.]*\])+", "\0" & @CRLF & @TAB), _
                                        "(?mi)([^\]\R])(?:\[[\d]*:[\d:.]*\])+", "\1"), _
                                        "(?mi)^((?:\[[\d]*:[\d:.]*\])+)\r\n\t", "\1")
                        GUICtrlSetData($Edit4, $sSRERe)
                Case $Button4 ;一步清理
                        Local $sEdit1 = GUICtrlRead($Edit1)
                        $sSRERe = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sEdit1, _
                                        "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\2."), _
                                        "(?mi)^(?:\[[\d]*:[\d:.]*\])+", "\0" & @CRLF & @TAB), _
                                        "(?mi)([^\]\R])(?:\[[\d]*:[\d:.]*\])+", "\1"), _
                                        "(?mi)^((?:\[[\d]*:[\d:.]*\])+)\r\n\t", "\1")
                        GUICtrlSetData($Edit4, $sSRERe)
                Case $Button5
                        RegExp(1)
                Case $Button6
                        RegExp(2)
                Case $Button7
                        RegExp(3)
                Case $Button8
                        RegExp(4)
        EndSwitch
WEnd

Func RegExp($vVar1) ;分步测试
        Local $sEdit1 = GUICtrlRead($Edit1)
        Local $sEdit4 = GUICtrlRead($Edit4)
        GUICtrlSetData($Edit3, '第1次行尾换行替换参数:' & @CRLF & '"(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\2."' & @CRLF & _
                        '第2次行首用TAB断行替换参数:' & @CRLF & '"(?mi)^(?:\[[\d]*:[\d:.]*\])+", "\0" & @CRLF & @TAB' & @CRLF & _
                        '第3次行中清理替换参数:' & @CRLF & '"(?mi)([^\]\R])(?:\[[\d]*:[\d:.]*\])+", "\1"' & @CRLF & _
                        '第4次首用TAB并上行替换参数:' & @CRLF & '"(?mi)^((?:\[[\d]*:[\d:.]*\])+)\r\n\t", "\1"')
        Switch $vVar1
                Case 1
                        $sSRERe = StringRegExpReplace($sEdit1, "(?mi)^(.+)(\[[\d]*:[\d:.]*\])\h*$", "\1" & @CRLF & "\2.")
                Case 2
                        $sSRERe = StringRegExpReplace($sEdit4, "(?mi)^(?:\[[\d]*:[\d:.]*\])+", "\0" & @CRLF & @TAB)
                Case 3
                        $sSRERe = StringRegExpReplace($sEdit4, "(?mi)([^\]\R])(?:\[[\d]*:[\d:.]*\])+", "\1")
                Case 4
                        $sSRERe = StringRegExpReplace($sEdit4, "(?mi)^((?:\[[\d]*:[\d:.]*\])+)\r\n\t", "\1")
                Case Else
                        
        EndSwitch
        GUICtrlSetData($Edit4, $sSRERe)
EndFunc   ;==>RegExp





发表于 2020-9-12 10:32:22 | 显示全部楼层
Local $string = _
'[ti:歌名]' & @CRLF & _
'[offset:-1000]' & @CRLF & _
'[:]增强版卡啦OK式LRC歌词转换成LRC简装版格式的正则是?' & @CRLF& @CRLF & _
'[00:02]歌手' & @CRLF & _
'[00:04.10]歌名' & @CRLF & _
'[00:06.10]专辑名[00:08.10]' & @CRLF & _
'[00:10:100]卡啦OK式歌词' & @CRLF & _
'[00:20.10]卡[00:21.10]啦[00:22.10]OK[00:23.10]式[00:24.10]歌[00:25.10]词[00:28.10]' & @CRLF & _
'[00:30.10][00:40.10][01:10.10]卡啦OK式歌词' & @CRLF & _
'[00:50.10][00:55.10]格式[错误][[00:57.10]]的歌词' & @CRLF & _
'[01:05.10]卡啦[:[01:05.10]]OK[[01:05.10]:]式歌词' & @CRLF & _
'[123:59.74]卡啦OK式歌词[123:10][124:10]' & @CRLF & _
'[格式]]错误[00:60.75]的[歌词]'


$string=StringRegExpReplace($string,'(?m)(.+?)(\[[\d\.:]+?\])+$','$1'&@CRLF&'$2\.')
$string=StringRegExpReplace($string,'(?m)([^\]])(\[[\d\.:]+\])','$1')
ConsoleWrite($string)
 楼主| 发表于 2020-9-14 09:04:31 | 显示全部楼层
haijie1223 发表于 2020-9-12 10:32
Local $string = _
'[ti:歌名]' & @CRLF & _
'[offset:-1000]' & @CRLF & _

谢谢,试试先。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-1 07:37 , Processed in 0.069354 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表