8

$ matches at the end of a line, not the end of a string. If you want to match at the end of a string you need to use the \' operator: (string-match "\n.*\\'" "\n \n \n ") => 4 See (info "(elisp)Regexp Backslash") for more details (or Regexp-Backslash)


7

Going by the Emacs source code, it is absolutely possible to use more than 9 regex capture groups: /* Since we have one byte reserved for the register number argument to {start,stop}_memory, the maximum number of groups we can report things about is what fits in that byte. */ #define MAX_REGNUM 255 /* But patterns can have more than 'MAX_REGNUM' ...


3

M-: (query-replace-regexp foo "bar") RET


3

If you want to check it interactively: (defcustom foo "" "foo" :type 'regexp :group 'emacs) Try giving it an invalid regexp and setting it, and it will raise an error. Or if you want to test it programmatically, this predicate returns t for valid and nil for invalid, and when invalid it shows a message with the error type. (defun regexp-...


3

I don't use evil mode, so I've no idea if its regexes are different from ordinary Emacs regexes or not. But if you use M-x re-builder, you'll see that "\\((?\\w*)?\\) *।" is a perfectly fine regex that matches all of your examples, with the group matching exactly what you want.


2

An Elisp regexp can't express this, AFAIK. (Some regexp dialects can.) But you can do it in two steps: Mark oil matches, which will include some wip matches. UNmark wip matches. There seems to be no command image-dired-unmark-tagged-files. But you can define one, just by binding dired-marker-char to a space char and "marking" with that. Like ...


2

For the most part, the syntax of regular expressions is defined compositionally: \(?:REGEXP1\)\|\(?:REGEXP2\) matches exactly what either REGEXP1 or REGEXP2 by definition of the \| operator. However, there is one exception: backreferences. Each use of parentheses declares a numbered group, and a backreference \DIGIT matches the group with the given (single-...


2

In elisp you normally search for what you're looking for in a loop, potentially establishing sub-groups of interest, and then you act on the match data if the search succeeded. Here you can simply replace every , with 、 within the subgroup. (save-excursion (while (re-search-forward "^[A-Z]+、\\(\\(?:[A-Z]+, \\)+\\)" nil t) (goto-char (match-...


2

Is this for interactive use? I suppose so. As the doc string for replace-regexp says: This function is for interactive use only; in Lisp code use `re-search-forward' and `replace-match' instead. Are you really asking about replace-regexp, and not query-replace-regexp? Because if you use the latter then the answer is included in Isearch by default: ...


2

THIRD EDIT (added after @Inspired_Blue's answer) @Inspired_Blue I did not try to completely follow and understand your answer. But as a matter of feedback, I will post here my way of solving the problem. While incidentally it inserts the correct times, you should still add functions to get the correct times for the general case. I strongly recommend you to ...


2

Pass a TESTFN arg to assoc. It needs to use string-match-p with the args reversed. That is, assoc passes TESTFN the pattern arg second, but string-match-p expects the pattern as its first arg. (assoc ".*ine" trees (lambda (x regexp) (string-match-p regexp x))) I filed doc bug report #50110 for this, asking that the arg order for optional arg ...


2

I don't think you want to just use a single regexp to search for defcustoms that have either :set or :initialize, with (or without) any of those things possibly being on different lines. Why? Because a single regexp to find either :set or :initialize, or both, in either order, is complicated. Instead, you want to use Lisp syntax: find (defcustom but search ...


2

M-C-% \(([[:digit:]]+)\) RET fixed text \1 RET ! RET means to press the return key. Some Explanation M-C-% runs the command query-replace-regexp in a typical Emacs. \(([[:digit:]]+)\) is the regexp for the occurances to be found like e.g. (1), (2) or (42). [:digit:] is the character class for digits. See e.g. the Elisp info pages for more. [[:digit:]] ...


1

Here is a way to do that: I collect each heading, then replace the buffer with just the headings. This also preserves properties on headlines: (defun strip-headings () (interactive) (setf (buffer-string) (string-join (cl-loop for headline in (org-element-map (org-element-parse-buffer) 'headline 'identity) collect (...


1

Looking at the code of evil-ex-substitute (using C-h f), the value for case-replace is set to the value of case-fold-search in the let* form. So it looks like there is no configuration option provided for this by default. But of course you can just replace the case-fold-search with (not case-fold-search) after the case-replace in that let* and (re)evaluate ...


1

@dalanicolai's se-answer function (see here), I believe, is superior to my solution as mine uses regular expressions and hence is possibly slower. Hence I accept his solution as the answer to this question. However I will share my solution here as well (for anyone who may learn something new from code snippets on stackexchange, like I do): (defun my-count-...


1

You can do that simply by recording the search for that regexp as the first part of your macro and using M-0<f4> to execute the macro -- per the Q&A you linked to, a prefix arg of zero repeats the macro indefinitely until you type C-g or an error occurs (which is what will happen when the search fails). Refer also to C-hig (emacs)Basic Keyboard ...


1

You can do an interactive regexp search via the command isearch-forward-regexp, bound to M-C-s by default. You can search for any upper-case letter via [A-Z], or [[:upper:]]. This will take you to the first capital after point. Pressing C-s will move to the next, which you can repeat. To do this from elisp code, you can use the function search-forward-regexp....


1

In reading the doc of query-replace-regexp, it mentions the \, syntax in the replacement text part, but not in the regex part: In interactive calls, the replacement text can contain ‘,’ followed by a Lisp expression. So AFAICT, you cannot do what you want interactively: you'd have to write your own souped-up version of query-replace-regexp as @choroba ...


1

First, note that query-replace-regexp matches either from the point to the end of the buffer or in the active region. So if your point is after what you are trying to match it will not work. With that out of the way, the following works for me: M-x query-replace-regexp RET <div class="copyright"> C-q C-j RET test RET And you should get a ...


1

anything matches any character, while regexp . matches any character except a newline, the rx representation is not-newline. *? matches zero-or-more, non-greedy. Let's extract comment from C code: /* comment */ char *s = "*/"; ;; * is zero-or-more, greedy (let ((string "/* comment */ char *s = \"*/\"")) (when (string-match (...


1

Here's the corrected incantation: (defun my-citekey-get-author-and-year () "Get the AUTHOR and YEAR from a cite:AUTHORYEARtitle key." (interactive) ; allow this to be user-callable (let ((regexp ":\\(.*\\)\\([0-9]*\\)[a-z]") ; the regex to parse (citekey (buffer-substring (line-beginning-position) ...


1

If LITERAL is nil then you can use "\\&" in the replacement to represent the entire matched string, and so your replacement text could be "PREFIX\\&". Refer to C-h f replace-match for the behaviour of LITERAL. (And if you didn't want special characters in the replacement text to be processed, you would generally want LITERAL to be ...


1

alternatively copy everything [matching] this regexp into another buffer. You can do that with occur C-uM-so : \([0-9,.]+\)$ RET \1 RET Or, if less-specific is fine, just: C-uM-so [0-9,.]+$ RET


1

Just use query-replace-regexp with .*?\([0-9\,\.]+\)$ → \1. And then keep-lines with the same regexp.


1

I have exactly the same issue in a different language (but similarly odd, from the sound of it). Let's start with a single keyword to match: "write" You can build up a solution starting with the regular expression provided in this answer (or actually one of its comments) about matching a word and all initial substrings: w(?:r(?:i(?:t(?:e)?)?)?)? ...


Only top voted, non community-wiki answers of a minimum length are eligible