0

Good afternoon. Difficulties with creating a regular expression for this function. Interested in finding a double quotation mark or back quotation mark. Attempts at use were unsuccessful:

(re-search-forward "\"\\|`" $z_poz t)
(re-search-forward "\"\|`" $z_poz t)
(re-search-forward "\"|`" $z_poz t)

The alternative character is followed by a back quotation mark. Thank you.

4
  • Your first attempt was correct (assuming you wish to search for either " or `), so your problem isn't what you think it is. What is your problem?
    – phils
    Commented Jun 27, 2022 at 10:08
  • Yes you are right, the errors were not in the regular expression
    – uanr81
    Commented Jun 27, 2022 at 19:54
  • Thanks for editing Muihlinn, I couldn't insert a back quotation mark
    – uanr81
    Commented Jun 27, 2022 at 19:59
  • 1
    I’m voting to close this question because the problem has been left unstated.
    – phils
    Commented Jun 27, 2022 at 20:39

2 Answers 2

1

You need to use

"[\"`]" 

for the regexp part.

It is easier to build regular expressions with rx or rx-to-string.

Here is a demo using M-x ielm.

*** Welcome to IELM ***  Type (describe-mode) or press C-h m for help.
ELISP> (rx-to-string '(or "`" "\""))
"[\"`]"
ELISP> 
3
  • They don't "need" to use that. What they did initially was equally valid.
    – phils
    Commented Jun 27, 2022 at 10:11
  • rx is the way to go; you’ll soon get LTS otherwise.
    – db48x
    Commented Jun 27, 2022 at 12:11
  • As far as you know, the inverse of a character class doesn't really matter.
    – uanr81
    Commented Jun 27, 2022 at 13:55
0

The function does work with the expression, the mistake was poor tracking of the position of the point. Below code

    (defun otmKvhk()
      "Отметка выражений в кавычках
    Обрабатывается выделенный регион
    Отмечается только крайние кавычки, вложения пропускаются,
    начало соответствия 'bbo# ', конец ' #obb'"
      (interactive)
      (let ((n_pozRgn (region-beginning)) (z_pozRgn (region-end)) n_svpd k_svpd)
        (goto-char n_pozRgn)
        (while (setq n_svpd (re-search-forward "\"\\|`" z_pozRgn t))
          (let ((data (match-data)))
        (unwind-protect
            (if (setq k_svpd (search-forward (match-string-no-properties 0) z_pozRgn t))
            (progn (insert " #obb")
                   (setq k_svpd (+ 5 k_svpd))
                   (setq n_svpd (- n_svpd 1))
                   (goto-char n_svpd)
                   (insert "bbo# ")
                   (setq k_svpd (+ 5 k_svpd))
                   (goto-char k_svpd)
                   (setq z_pozRgn (+ 10 z_pozRgn)))
              (error "%s" "Не найдено соответствие!")
              )
          (set-match-data data)))
          )
        (goto-char z_pozRgn))
      )
1
  • n.b. C-h f save-match-data
    – phils
    Commented Jun 27, 2022 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.