Skip to main content

Questions tagged [query-replace-regexp]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
81 views

query-replace: ignore events not binded in query-replace-map

I have this function: (defun my-replacements () (interactive) (query-replace "foo" "bar" nil (point-min) (point-max)) (query-replace "baz" "quz" nil (...
Gabriele's user avatar
  • 1,662
0 votes
1 answer
62 views

query-replace bug?

When I run query-replace* commands if I type ? I get this explanation of the function's options: Type Space or ‘y’ to replace one match, Delete or ‘n’ to skip to next, RET or ‘q’ to exit, Period to ...
Gabriele's user avatar
  • 1,662
0 votes
0 answers
20 views

How to enter query-replace-regexp with key binding C-M-%, if emacs session is not stand-alone but in mate-terminal running Bash?

Title says it all. The problem: When you start emacs within a terminal running a shell, Meta and Ctrl key act in strange ways: In some regards they work, in others, however, not as it used to be ...
starquake's user avatar
0 votes
2 answers
66 views

How can a regex replace that computes the replacement in a function using back references be converted to a CLI batch version processing line by line?

An example of this is a script to output the contents of .zsh_history file in the manner of the history command, so an emacs script would be invoked by a command line like display.sh.el < ~/....
vfclists's user avatar
  • 1,433
0 votes
1 answer
153 views

Am I using "replace-regexp-in-string" the right way?

I want to view ~/.zsh_history files the way they are displayed by the history command with raw unixtimestamps converted to properly formatted dates. : 1568128379:0;cp -a ~/.zshrc.pre-oh-my-zsh ~/....
vfclists's user avatar
  • 1,433
0 votes
2 answers
103 views

Is it possible for a query-replace-regexp to replace the value with a computed value?

I want to convert the timestamps in a .zsh_history file to their readable equivalents. Does query-replace-regex or some other function provide the ability to replace the match with the value of a ...
vfclists's user avatar
  • 1,433
1 vote
1 answer
145 views

Function to replace strings from region and save result in kill-ring

I'm almost completely ignorant in elisp, but I'd like to have a function that does the following: Takes a string from (a) a region, if one is selected, or (b) user prompt, if a region is not selected....
pglpm's user avatar
  • 325
0 votes
2 answers
93 views

How can I interactively replace text in all files in all subfolders?

Emacs 27.1 Linux Mint 21 I have text modifyNetwork in 50 files in differents folders. I need to replace them by text performCommand. What is the easiest way to replace text in all files in all ...
a_subscriber's user avatar
  • 4,174
0 votes
1 answer
25 views

Regexp for first consecutive non whitespace ending with @?

I have a mailing list whose lines contain garbage characterized by spaces, like this: bar qux [email protected] for which I want to extract [email protected]. I tried this unsuccessfully: M-x query-replace-...
user avatar
0 votes
1 answer
47 views

isearch-forward-regex does not find a regex found by re-builder

I wanted to create a regex to find these dates: 1966/08/20 2023/02/12 In re-builder I was able to build this: "\([0-9]\{4\}\)/\([0-9]\{2\}\)/\([0-9]\{2\}\)" In the buffer the dates are ...
Edman's user avatar
  • 1,229
0 votes
1 answer
20 views

Efficient way to change the format of a date in orgmode

enter code hereWhat would be the most efficient way to change the format of a list of dates like this in Emacs: |Bob|1966/08/20|2023/05/19| |Janice|1964/09/18|2023/05/19| To this: |Bob|<1966-08-20&...
Edman's user avatar
  • 1,229
1 vote
1 answer
171 views

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 ...
starquake's user avatar
2 votes
2 answers
83 views

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 " ...
Onner Irotsab's user avatar
0 votes
1 answer
88 views

Highlight query-replace-regexp results while searching

I am terrible at remembering regular expression syntax. When replacing in by buffer with a regexp, I would like Emacs to highlight the possible matches while I am typing the regexp, so that I can see ...
Arthur Azevedo De Amorim's user avatar
0 votes
1 answer
84 views

Using query-replace-regex to partially replace

I'm struggling with the basics of query-replace-regex after reading the manual. I'm trying to replace lots of citations formatted like this: #123213213, foo bar to #123213213\, foo bar the numbers ...
user13495873's user avatar
0 votes
1 answer
55 views

Is it possible to mimic sed's "change line" feature?

I'd like to write an elisp function that allows me to replace any line in my buffer matching a regex pattern <PATTERN> with text <TEXT>. In other words, if line N matches <PATTERN>, ...
Brian Fitzpatrick's user avatar
0 votes
1 answer
24 views

regexp fails over expression involving {}

Over: \includepdf[pages={1-}]{example-image-a.pdf} I do / get M-x query-replace-regexp \\includepdf[pages={1-}]{.*} → \\includepdf[pages={1-}]{TEST} Replace 0 occurrences The problem comes from the ...
user avatar
0 votes
0 answers
34 views

What's the meaning of the error: Point 95406 after end of properties?

What's the meaning of the error: Point 95406 after end of properties? I identified the piece of code that produces this error (blocking my script): ;; "Fig" --> "Figure" ;; &...
Gabriele's user avatar
  • 1,662
1 vote
1 answer
35 views

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 ()...
Gabriele's user avatar
  • 1,662
2 votes
1 answer
229 views

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 ...
Onner Irotsab's user avatar
0 votes
1 answer
63 views

Find and recursively delete (with query) consecutive duplicate words not necessarily in the same line and/or same case

I would like to scan through a (latex) document and recursively delete -- WITH QUERY -- all consecutive, repeated words that need not be on the same line and/or the same case. Here is a simple ...
underflow's user avatar
  • 111
1 vote
2 answers
21 views

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 ...
mikemtnbikes's user avatar
0 votes
0 answers
101 views

Why doesn't project-query-replace-regexp work well

It seems promising to have a built-in function that performs this action: find and replace all matching text recursively, within your project. The problem is that it doesn't seem consistent. I am ...
mcp's user avatar
  • 556
2 votes
2 answers
65 views

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 ...
Byron Dom's user avatar
0 votes
1 answer
125 views

How to replace (blah) with {blah} for a specific string

In a latex document, I wish to replace \cost(blah) with \cost{blah} in the entire document, where blah is an arbitrary string. That is, I only want to change the round brackets to curly brackets for ...
Vikram's user avatar
  • 337
0 votes
1 answer
206 views

Search and Replace for a block on many lines in a dozen files

I have a a bunch of HTML files and in each of them I want to replace a fixed block of approx 30 lines with a one liner. Is there an Emacs command or package which makes this easier? Using e.g. dired-...
halloleo's user avatar
  • 1,345
1 vote
1 answer
240 views

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.
HappyFace's user avatar
  • 830
0 votes
1 answer
53 views

Automatically save files after multi-file search/replace

How can I get GNU Emacs to automatically save all the files I've changed after doing a multi-file search/replace with query-replace-regexp? Right now I have to switch back to the buffer for every ...
cjg's user avatar
  • 1
1 vote
2 answers
389 views

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 ...
Hi-Angel's user avatar
  • 798
3 votes
1 answer
105 views

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 ...
vinc17's user avatar
  • 183
3 votes
2 answers
1k views

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 ...
zcal's user avatar
  • 31
2 votes
1 answer
53 views

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(...
Ambrose's user avatar
  • 23
1 vote
1 answer
80 views

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, } ...
zoldseges's user avatar
1 vote
0 answers
58 views

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 &...
Onner Irotsab's user avatar
1 vote
1 answer
99 views

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 ...
Michael Terry's user avatar
0 votes
1 answer
34 views

.+$ fails to match remainder of line

This matches nothing: Query replace regexp (default \.org.+ → ): \.org.+$ → The same without '$' matches incompletely: I'd like to be able to match \.org and all that follows.
user avatar
0 votes
1 answer
144 views

Regexp: how to search-replace any html attribute in current buffer

Disclaimer: I'm still trying to learn elisp so I have not gotten yet to the RegExp section of the Elisp intro or Emacs manual. I would like to know how to search and replace an HTML buffer that has ...
avocadoras's user avatar
1 vote
1 answer
311 views

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 ...
alper's user avatar
  • 1,400
0 votes
2 answers
129 views

query-replace{-regexp} fails in linux in a non-X terminal when I am in anything other than text mode

I am running emacs 26.1 under linux. It has been working fine for over a year. Recently, I upgraded a lot of packages on my machine, but I did not upgrade nor alter emacs in any way. Now, query-...
HippoMan's user avatar
  • 616