2

获取“行尾的等号 ( =$),加上紧随其后的“换行符””的正则表达式语法是什么?

我的文本格式错误(真的坏了),如下所示:

Tiens, encore du HTML, batard rouge, et un charact=C3=A8re accentu=C3=A9, P=
=C3=80F

(每一行都以 = 结尾)所以我想抓住的是字面上的

"=
"

我用下面粘贴的函数处理它。

但我也想加入这些行,即删除换行符,但我无法M-x regexp-builder突出显示最后一个“=”符号后面的换行符,以便我可以用空字符串“”替换它并因此加入线..?

(setq entities
  '(("=C3=A9" "é")
    ("=C3=89" "É")
    ("=C3=A8" "è")
    ("=C3=88" "È")
    ("=C3=A7" "ç")
    ("=C3=87" "Ç")
    ("=C3=A0" "à")
    ("=C3=80" "À")
    ("=C3=B9" "ù")
    ("=C3=99" "Ù")
    ("=C3=AA" "ê")
    ("=C3=8A" "Ê")
    ("=C3=BB" "û")
    ("=C3=9B" "Û")
    ("=C3=AB" "ë")
    ("=C3=8B" "Ë")
    ("=C3=BC" "ü")
    ("=C3=9C" "Ü")
    ("=20" "")
    ("=3D\"" "=\"")
    ("=$" "")))

(defun px-decode-string (string entities)
  "decode a string against a list of entities / chars pairs."
  (setq i 0)
  (while (< i (length entities))
    (setq my-operand (format "%s" (car (car (nthcdr i entities)))))
    (setq my-char (format "%s" (car (cdr (car (nthcdr i entities))))))
    (setq string (replace-regexp-in-string my-operand my-char string 't))
    (setq i (1+ i))
    )
  (format "%s" string))

(alist 是 asetq而不是 adefvar仅用于测试目的)

测试:

(px-decode-string "Tiens, encore du HTML, batard rouge, et un charact=C3=A8re accentu=C3=A9, P=
=C3=80F!
" entities)
4

2 回答 2

3

在字符串文字中,您可以使用“\n”而不是“$”来匹配换行符。

交互式地,例如query-replace-regexp,使用C-q C-j.

于 2012-08-04T02:08:47.603 回答
0

好吧,没关系,我找到了:=\n

于 2012-08-04T02:08:30.457 回答