#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