![](/img/trans.png)
[英]Unable to match a multiline regex with Powershell (but it does work in C#)
[英]Powershell multiline regex: subtitles , How?
在此網站上: http : //softwarerecipes.blogspot.com/2011/01/powershell-script-for-fixing-subtitles.html 。 有用於修復字幕文件偏移的腳本,如下所示:
SrtFixer.ps1-路徑“ Movie.srt”-偏移量“ -00:00:26.700”,但不可用。
所以我在C#中找到了一個腳本(在這里: http : //www.codeproject.com/Articles/32834/Subtitle-Synchronization-with-C )
我的第一步是為以下結構編寫正確的正則表達式:
2
00:00:01,775 --> 00:00:04,528
- I want you to admit what you are.
- You still refuse to see
我會嘗試的:
$file = "D:\subtitles\Hannibal - 02x10 - eng.srt"
$regex ='(?m)[0-9]{1,5}\n([0-9]{2}:[0-9]{2}:[0-9]{2}),([0-9]{3}) --> ([0-9]{2}:[0-9] {2}:[0-9]{2}),([0-9]{3})\n((.+\n)*)'
$text =get-content($file) -Raw
$text | Select-String $regex -AllMatches |
Foreach {$_.Matches} | Foreach {$_.Value}
正則表達式似乎正確(regexhero),但沒有任何匹配項。
你能幫助我嗎 ?
編輯:
我的錯。 正確的正則表達式
$regex ='(?m)[0-9]{1,5}\n([0-9]{2}:[0-9]{2}:[0-9]{2}),([0-9]{3})\s-->\s([0-9]{2}:[0-9]{2}:[0-9]{2}),([0-9]{3})\n((.+\n)*)'
但這不起作用。
正則表達式是不正確的,至少在與Regex Coach和您的示例文本一起檢查時才如此。 這是因為([0-9]{2}:[0-9] {2}:[0-9]{2})
在時間戳內需要一些奇數間距。 刪除這些將為樣本輸入提供匹配。
話雖這么說,如何獲得內容的付費版本? 那些通常具有良好的字幕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.