all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Replace all occurrences of a specific character with another.
@ 2023-07-22 14:35 Hongyi Zhao
  2023-07-22 15:07 ` PierGianLuca
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Hongyi Zhao @ 2023-07-22 14:35 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

Hi here,

I want to replace all occurrences of a specific character, say, `d`,
as shown in the attached screenshot, with another character, e.g.,
`n`. Is there any practical way to do this?

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 195823 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Replace all occurrences of a specific character with another.
  2023-07-22 14:35 Replace all occurrences of a specific character with another Hongyi Zhao
@ 2023-07-22 15:07 ` PierGianLuca
  2023-07-23  0:36   ` Hongyi Zhao
  2023-07-23  2:18 ` Michael Heerdegen
  2023-07-25 17:00 ` Emanuel Berg
  2 siblings, 1 reply; 6+ messages in thread
From: PierGianLuca @ 2023-07-22 15:07 UTC (permalink / raw)
  To: help-gnu-emacs

It looks like your character appears surrounded by non-letters in every instance. In this case you could use `query-replace-regexp` replacing

\<d\>

with

n

The "\<\>" brackets match beginning and end of words:

https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-
Backslash.html


Your character also seems to appear inside maths expressions only. In this case you could use the function defined in this post:

http://stackoverflow.com/questions/19845598/emacs-regex-replacing-a-string-inside-a-latex-equation

it's very useful and I use it regularly in LaTeX documents.

Cheers,
Luca


On 230722 16:35, Hongyi Zhao wrote:
> Hi here,
> 
> I want to replace all occurrences of a specific character, say, `d`,
> as shown in the attached screenshot, with another character, e.g.,
> `n`. Is there any practical way to do this?
> 
> Regards,
> Zhao



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Replace all occurrences of a specific character with another.
  2023-07-22 15:07 ` PierGianLuca
@ 2023-07-23  0:36   ` Hongyi Zhao
  2023-07-23 10:23     ` PierGianLuca
  0 siblings, 1 reply; 6+ messages in thread
From: Hongyi Zhao @ 2023-07-23  0:36 UTC (permalink / raw)
  To: PierGianLuca; +Cc: help-gnu-emacs

On Sat, Jul 22, 2023 at 11:08 PM PierGianLuca
<luca@magnaspesmeretrix.org> wrote:
>
> It looks like your character appears surrounded by non-letters in every instance. In this case you could use `query-replace-regexp` replacing
>
> \<d\>
>
> with
>
> n
>
> The "\<\>" brackets match beginning and end of words:
>
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-
> Backslash.html
>
>
> Your character also seems to appear inside maths expressions only. In this case you could use the function defined in this post:
>
> http://stackoverflow.com/questions/19845598/emacs-regex-replacing-a-string-inside-a-latex-equation

Thank you for the nice tip, but there are several versions of
functions suggested there. So, which one is your preferred version?

> it's very useful and I use it regularly in LaTeX documents.
>
> Cheers,
> Luca

Regards,
Zhao

> On 230722 16:35, Hongyi Zhao wrote:
> > Hi here,
> >
> > I want to replace all occurrences of a specific character, say, `d`,
> > as shown in the attached screenshot, with another character, e.g.,
> > `n`. Is there any practical way to do this?
> >
> > Regards,
> > Zhao



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Replace all occurrences of a specific character with another.
  2023-07-22 14:35 Replace all occurrences of a specific character with another Hongyi Zhao
  2023-07-22 15:07 ` PierGianLuca
@ 2023-07-23  2:18 ` Michael Heerdegen
  2023-07-25 17:00 ` Emanuel Berg
  2 siblings, 0 replies; 6+ messages in thread
From: Michael Heerdegen @ 2023-07-23  2:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> Hi here,
>
> I want to replace all occurrences of a specific character, say, `d`,
> as shown in the attached screenshot, with another character, e.g.,
> `n`. Is there any practical way to do this?

The screenshot shows something different.  I answer the screenshot:

Depending on the mode, start isearching using word or symbol mode (M-s
w, M-s _) enter you search term and then M-% to query-replace the word or
symbol.

"Depending" means it depends on the syntax table of the current mode if
that is exactly what you want, or more, or less matches.  And if I
guessed correctly what you want.

Michael.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Replace all occurrences of a specific character with another.
  2023-07-23  0:36   ` Hongyi Zhao
@ 2023-07-23 10:23     ` PierGianLuca
  0 siblings, 0 replies; 6+ messages in thread
From: PierGianLuca @ 2023-07-23 10:23 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Zhao,

You're welcome.

> Thank you for the nice tip, but there are several versions of
> functions suggested there. So, which one is your preferred version?

I use this, on Emacs 28:

https://stackoverflow.com/a/44913296/6090141

and it works for me.

Cheers,
Luca



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Replace all occurrences of a specific character with another.
  2023-07-22 14:35 Replace all occurrences of a specific character with another Hongyi Zhao
  2023-07-22 15:07 ` PierGianLuca
  2023-07-23  2:18 ` Michael Heerdegen
@ 2023-07-25 17:00 ` Emanuel Berg
  2 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2023-07-25 17:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> I want to replace all occurrences of a specific character,
> say, `d`, as shown in the attached screenshot, with another
> character, e.g., `n`. Is there any practical way to do this?

A loop with `re-search-forward' and `replace-match', see

  https://dataswamp.org/~incal/emacs-init/regexp.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-25 17:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-22 14:35 Replace all occurrences of a specific character with another Hongyi Zhao
2023-07-22 15:07 ` PierGianLuca
2023-07-23  0:36   ` Hongyi Zhao
2023-07-23 10:23     ` PierGianLuca
2023-07-23  2:18 ` Michael Heerdegen
2023-07-25 17:00 ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.