我試圖格式選項卡的多行分隔下面調用replace-match時,如何評估替換字符串中的lisp表達式?
ID Name Duration Start_Date Finish_Date Predecessors Successors Resource_Group Deadline Constraint_Type
形式的數據轉換成使用下面的Lisp代碼字段列表。
(while (re-search-forward "\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)\t\\(.*\\)" nil t)
(replace-match
"* \\2
:PROPERTIES:
:task_id: \\1
:duration: \\3
:start: \\4
:finish: \\5
:predecessors: \\6
:successors: \\7
:resource_group: \\8
:deadline: \\9
:constraint_type: \\,(match-string 10)
:END:"
nil nil))
代碼按預期執行,直到達到第10個回參考匹配的字符串。我發現一個解決方案來反引用大於9的組是使用lisp函數(match-string 10)。當以交互方式使用replace-regexp時,如果替換字符串中的lisp代碼被前綴爲'\,',並且./(match-string 10)的行爲與我期望的交互地調用replace-regexp時相同;
但是,上述代碼塊中的\\,(匹配字符串10)會產生錯誤。我已經嘗試了一,二,三,四等'',但它要麼產生相同的錯誤,要麼打印字符串。有誰知道使用此功能的方法或參考大於9的組號的方法嗎?
非常感謝!
你應該也可以upvote你自己選擇的正確答案。 – 2012-08-16 00:48:14
我該如何upvote?我是新人,在常見問題解答中找不到關於投票如何/爲什麼會起作用的任何內容。有關如何工作的任何提示將有所幫助,謝謝。 – user1593649 2012-08-17 13:44:22