我希望这个正则表达式将每个术语放在大括号内。但是如果有一个带有转义参数的术语将这个术语与下一个术语连接起来
(replace-regexp-in-string "{ " "{"
(replace-regexp-in-string "}{" "} {" (replace-regexp-in-string
"\\(.*?_.\\)" "{\\1}" "\Delta y_t u_t")))
期望的输出
y_t a_t ==> {y_t} {a_t}
\Delta y_t a_t ==> {\Delta y_t} {a_t}
答案 0 :(得分:1)
你可以尝试
(replace-regexp-in-string
"\\(\\(?:\\\\[^ \t]+[ \t]\\)?[^ \t]+\\)" "{\\1}" "z_t \\Delta y_t x_t")
使用与上一个答案相同类型的可选捕获组。
答案 1 :(得分:0)
试试这个,你可能需要调整反斜杠的数量
(replace-regexp-in-string "}{" "} {" (replace-regexp-in-string
"\(\(?:\\\w+ \)?\w+\)" "{\\1}" "\Delta y_t u_t")))