Questions tagged [query-replace-regexp]

32 questions
3
votes
1 answer

Equivalent of query-replace-regexp for multiple regexps

How can I do the equivalent of query-replace-regexp for multiple regexps? For instance, if regexp1 is matched, it should be replaced by text1, and if regexp2 is matched, it should be replaced by text2 (with interactive confirmation as with…
vinc17
  • 183
  • 6
2
votes
2 answers

How do you use a variable in the "replacement" part of query-replace-regexp?

I want to do simple replacements in a LaTeX source using something like that: ;; test-1 (query-replace-regexp (regexp-quote FOO) (concat "Foo " FOO ".") …
Onner Irotsab
  • 431
  • 2
  • 9
2
votes
1 answer

How to match two consecutive identical words except for the case of the initial characters?

I'm looking for a solution to match two consecutive identical words except for the case of the initial characters with query-replace-regexp: The the the The I can't figure out how to match these typos with a regular expression at once because I…
2
votes
2 answers

i have a regex that i want to apply only to the lines immediately following a \item line in a latex list. how do i do it?

I should mention that I want to do this in emacs with its version of regex. Here's an example. I would like to change - \item - Property Agreement - Your agreement changing Joint Tenancy - property into Community…
Byron Dom
  • 33
  • 4
2
votes
1 answer

Search and replace with many possible replacements?

Suppose I have a code base with many instances of string "console.log(" for example. I want to replace each one with one of the following six lines: logger(FATAL, logger(ERROR, logger(WARNING, logger(INFO, logger(LOG, logger(DEBUG, Each…
Ambrose
  • 23
  • 4
1
vote
1 answer

What is the replace regexp string for applying 3 digit grouping to any number?

the title gives it all away: I want this 9874599842006432.08 To become this 9,874,599,842,006,432.08 with 1 single replace regexp operation and flexible, so that the same string also would work on a shorter or longer number like for example…
starquake
  • 43
  • 6
1
vote
1 answer

Can replace-regexp-lax-whitespace manage "~" as a whitespace?

I have this function: (defvar biblio-publishers-info-list '(("Cambridge University Press" . "Cambridge, U.K.")) "DOCSTRING") (defun biblio-publishers-info-complete () "DOCSTRING. E.g.: Cambridge University Press (2013) --> Cambridge…
1
vote
2 answers

Matching non-# in Regexp

I'm trying to use replace-regexp to change the following code samples <- rep(10, 5)*1000 ## steps determined by samples * thin adaptive.ratio <- c(rep(c(1,0), 2), 0) ## Alternate between adaptive and non-adaptive ... to print(paste0("samples: ",…
mikemtnbikes
  • 223
  • 2
  • 9
1
vote
1 answer

evil: Make `%s/x/y/gc` use case insensitive matching but do case sensitive replaces

How do I make %s/x/y/gc use case insensitive matching but do case sensitive replaces? In emacs terms, I want case-fold-search but not case-replace.
1
vote
2 answers

Using a variable as the REGEXP in `query-replace-regexp`

I know, Emacs allows calling ELisp while replacing a text with a regex, aka C-M-%, which is bound to query-replace-regexp. I'm trying to make use of that to store an unwieldy regexp as a variable, so instead of writing it out every time, I could…
Hi-Angel
  • 525
  • 6
  • 18
1
vote
2 answers

How to find a newline with a regular expression in query-replace-regexp?

I am trying to use find-name-dired and query-replace-regexp to find and replace some blocks of text across multiple HTML files. (Just what is explained here in the Emacs Manual.) query-replace-regexp fails to match anything containing a…
zcal
  • 11
  • 3
1
vote
1 answer

How to duplicate text but increment a numeric part of a name?

Say that I have rect1 one and I'll multiply it 3 times by yanking. let rect1 = Rectangle { width: 10, height: 40, } let rect1 = Rectangle { width: 10, height: 40, } let rect1 = Rectangle { width: 10, …
1
vote
0 answers

How to replace a block of text with a "query-like" approach all at once?

I want to search and replace a block of text with a "query-like" approach all at once. For example, if I have \emph{``Foo $\bar$ baz''} to be replaced by \emph{Foo $\bar$ baz} using a "query-like" approach all at once, how could I do? I have tried…
Onner Irotsab
  • 431
  • 2
  • 9
1
vote
1 answer

How can I get the search string from incremental regexp search to use with replace regexp

If I want to do a replace-regexp I usually start with a isearch-forward-regexp so I can get immediate visual feedback on the search string. From there I'd like to grab the search string for using in the replace-regexp. Right now all I can see to do…
1
vote
1 answer

How to replace strings including `.` (dot) as first character using dired-do-find-regexp-and-replace

(defun my-find-orgfiles () (interactive) (find-name-dired "." "*py")) (global-set-key (kbd "M-n") 'my-find-orgfiles) Than, t to toggle marked/unmarked files (thus marking them all, since none were marked). Then I use Q to use query-replace on…
alper
  • 1,238
  • 11
  • 30
1
2 3