Questions tagged [query-replace-regexp]
The query-replace-regexp tag has no usage guidance.
28
questions
1
vote
1
answer
39
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 ...
2
votes
2
answers
36
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 "
...
0
votes
1
answer
28
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 ...
0
votes
1
answer
32
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 ...
0
votes
1
answer
32
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>, ...
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 ...
0
votes
0
answers
30
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"
;; &...
1
vote
1
answer
34
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 ()...
2
votes
1
answer
176
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 ...
0
votes
1
answer
35
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 ...
1
vote
2
answers
20
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 ...
0
votes
0
answers
43
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 ...
2
votes
2
answers
60
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 ...
0
votes
1
answer
64
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 ...
0
votes
1
answer
120
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-...
1
vote
1
answer
73
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.
0
votes
1
answer
35
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 ...
1
vote
2
answers
210
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 ...
3
votes
1
answer
72
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 ...
1
vote
1
answer
549
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 ...
2
votes
1
answer
51
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(...
1
vote
1
answer
46
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,
}
...
1
vote
0
answers
55
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 &...
1
vote
1
answer
86
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 ...
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.
0
votes
1
answer
102
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 ...
1
vote
1
answer
237
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 ...
0
votes
2
answers
115
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-...