2017-07-25 42 views
0

之間更換EOL在多線串是這樣的:正則表達式:發現和報價

She Loves You [Mono],"Past Masters, Vol. 1",4,"She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah, yeah" 
Eight Days A Week,Beatles For Sale,8,"Eight days a week 
I love you. 
Eight days a week 
Is not enough to show I care." 

我想更換EOL(\ r \ n)的報價包含「替換字符之間¶ 「(ASCII碼182)來使這個字符串單行。

其結果將是:

She Loves You [Mono],"Past Masters, Vol. 1",4,"She loves you, yeah, yeah, yeah¶She loves you, yeah, yeah, yeah¶She loves you, yeah, yeah, yeah, yeah" 
Eight Days A Week,Beatles For Sale,8,"Eight days a week¶I love you.¶Eight days a week¶Is not enough to show I care." 

我試圖在計算器上發現的各種正則表達式相關的解決方案,但我不能給他們適應我想要的東西。

我將在AHK函數中使用這個表達式表達:

RegExReplace(Haystack, NeedleRegEx [, Replacement = "", OutputVarCount = "", Limit = -1, StartingPosition = 1]) 

RegExReplace(MyText, NeedleRegEx???, "¶") 

任何幫助表示讚賞。

+0

不,它不會修復它。挑戰是隻在報價之間進行更換。 – JnLlnd

+0

我會讓我的問題更清楚。 – JnLlnd

+0

我的問題不夠清楚。我只在標題中提到了「之間的引號」要求,並沒有再提出問題本身。對於那個很抱歉。請參閱編輯的問題。 – JnLlnd

回答

0

你可以解析字符串並以這種方式進行操作嗎?

str = 
(
She Loves You [Mono],"Past Masters, Vol. 1",4,"She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah, yeah" 
Eight Days A Week,Beatles For Sale,8,"Eight days a week 
I love you. 
Eight days a week 
Is not enough to show I care." 
) 
outStr := "" 
Loop, Parse, str, `" 
{ 
    field := A_LoopField 
    StringReplace, field, field, `r,, All 
    StringReplace, field, field, `n, ¶, All 
    outStr .= field 
} 
MsgBox % outStr 
ExitApp 
+0

我不是在尋找一個「簡單替代」。挑戰在於只在引號之間進行替換,而不是簡單的解決方案所做的全部替換。 – JnLlnd

+0

我會讓我的問題更清楚。 – JnLlnd

+0

你必須解析字符串。我修改了我的答案。 – fischgeek

0

因爲它似乎只存在沒有使用正則表達式的解決方案,我張貼在這裏通過maestrith寫(AHK上論壇)的解決方案。它確實取代了引號內的EOL,保留了引用封裝器。它使用StrSplit來讀取和處理整個內容以隔離引用段,並使用RegExReplace和StringReplace的組合來處理它們。我仍然需要在一個非常大的文件上測試它,看看它是如何執行的,與我編寫的另一個腳本相比,它一次只處理一個字符。

#SingleInstance,Force 
info= 
(
She Loves You [Mono],"Past Masters, Vol. 1",4,"She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah, yeah" 
Eight Days A Week,Beatles For Sale,8,"Eight days a week 
I love you. 
Eight days a week 
Is not enough to show I care." 
) 
for a,b in StrSplit(info,Chr(34)){ 
    if(!Mod(A_Index,2)){ 
     replace:=RegExReplace(b,"\R",chr(182)) 
     StringReplace,info,info,%b%,%Replace% 
    } 
} 
Gui,Font,s10 
Gui,Add,Edit,w1000 h200 -Wrap,%Info% 
Gui,Show 
0

即使沒有回答我的原始問題,我也會將其添加爲答案。這不使用正則表達式,但最終比早期答案中的試驗性更快(在3兆csv文件上大約快3倍到5倍)。

#SingleInstance,Force 
info= 
(
She Loves You [Mono],"Past Masters, Vol. 1",4,"She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah 
She loves you, yeah, yeah, yeah, yeah" 
Eight Days A Week,Beatles For Sale,8,"Eight days a week 
I love you. 
Eight days a week 
Is not enough to show I care." 
) 
blnInsideEncapsulators := false 
Loop, Parse, info 
    ; parsing on a temporary copy of info - so we can update the original info inside the loop 
{ 
    if (A_Index = 1) 
     info := "" 
    if (blnInsideEncapsulators AND A_Loopfield = "`n") 
     info := info . Chr(182) 
    else 
     info := info . A_Loopfield 
    if (A_Loopfield = """") 
     blnInsideEncapsulators := !blnInsideEncapsulators ; beginning or end of encapsulated text 
} 
Gui,Font,s10 
Gui,Add,Edit,w1000 h200 -Wrap,%Info% 
Gui,Show 

如果有人附帶完整的RegEx解決方案,我將離開此線程而不接受任何答案。永遠不知道...

謝謝大家的意見。