Questions tagged [query-replace-regexp]
The query-replace-regexp tag has no usage guidance.
38
questions
0
votes
0
answers
46
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 ...
0
votes
0
answers
16
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 ...
0
votes
2
answers
48
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 < ~/....
0
votes
1
answer
101
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 ~/....
0
votes
2
answers
96
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 ...
1
vote
1
answer
111
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....
0
votes
2
answers
79
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 ...
0
votes
1
answer
24
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-...
0
votes
1
answer
36
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 ...
0
votes
1
answer
14
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&...
1
vote
1
answer
126
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
63
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
64
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
44
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
48
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
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"
;; &...
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 ()...
2
votes
1
answer
210
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
51
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
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 ...
0
votes
0
answers
78
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
62
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
94
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
168
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
175
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
45
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
313
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
88
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
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 ...
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
63
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
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 &...
1
vote
1
answer
95
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
127
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
288
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
124
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-...