unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Replace regexp question
@ 2013-06-08  6:11 Leandro Marcolino
  2013-06-08 12:39 ` Andreas Röhler
  0 siblings, 1 reply; 9+ messages in thread
From: Leandro Marcolino @ 2013-06-08  6:11 UTC (permalink / raw)
  To: Help-gnu-emacs

Hello, all!..

I am trying to add text after multiple occurrences of a group, but it is not
working. For example, if I try to change the following: "aaaaaa" to
"aaaaaab", I end up with "ab"...

I am looking for the regexp: \(a\)+ and I replace by \1b. But then the
sequence of a's is reduced to a single "a". How can I make the final text
have the same number of occurrences of the group as the original text?..

Thank you very much for your help!..

Regards,
Leandro



--
View this message in context: http://emacs.1067599.n5.nabble.com/Replace-regexp-question-tp288179.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <mailman.634.1179145690.32220.help-gnu-emacs@gnu.org>]
* replace regexp question
@ 2007-05-14 10:33 Seweryn Kokot
  0 siblings, 0 replies; 9+ messages in thread
From: Seweryn Kokot @ 2007-05-14 10:33 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

Assume in a latex file I have a lot of occurences like these:
\begin{figure}[htbp]
  \centering
  \includegraphics{filename}
  \caption{Text}
  \label{fig:label}
\end{figure}
and
\begin{table}[htbp]
  \centering
  \caption{Text}
  \label{tab:label}
  \captab{tab:label}{text}{}
  \begin{tabular}{ccc}
  ...
  \end{tabular}
\end{table}

I want to change all occurences \caption and \label to get something
like these:
\begin{figure}[htbp]
  \centering
  \includegraphics{filename}
  \capfig{fig:label}{Text}{}
\end{figure}
and 
\begin{table}[htbp]
  \centering
  \captab{tab:label}{text}{}
  \begin{tabular}{ccc}
  ...
  \end{tabular}
\end{table}

So I wrote a function if .emacs

(defun my-caption-to-capfig ()
  "bar"
  (interactive)
  (while (re-search-forward 
          "\\\\caption\{\\(.*\\)\}\s*\n\s*\\\\label\{\\(.*\\)\}\s*\n\s*\\\\end\{figure\}" nil t)
	 (replace-match 
	  "\\\\capfig{\\2}{\\1}{}\n\\\\end{figure}")))
(defun my-caption-to-captab ()
  "foo"
  (interactive)
  (while (re-search-forward 
          "\\\\caption\{\\(.*\\)\}\s*\n\s*\\\\label\{\\(.*\\)\}\s*\n\s*\\\\begin\{tabular\}" nil t)
	 (replace-match "\\\\captab{\\2}{\\1}{}\n\\\\begin{tabular}")))

but sometimes \end{figure} and \begin{tabular} are indented and then after replacing I get it
without indent. How to take it into account in (replace-match "...") function?

regards,
Seweryn Kokot

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

end of thread, other threads:[~2013-06-08 17:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1206.1370689126.22516.help-gnu-emacs@gnu.org>
2013-06-08 12:41 ` Replace regexp question Pascal J. Bourguignon
2013-06-08 16:44   ` Leandro Marcolino
2013-06-08 16:46     ` Leandro Marcolino
2013-06-08 17:27       ` Leandro Marcolino
2013-06-08  6:11 Leandro Marcolino
2013-06-08 12:39 ` Andreas Röhler
     [not found] <mailman.634.1179145690.32220.help-gnu-emacs@gnu.org>
2007-05-14 19:00 ` replace " Ralf Angeli
2007-05-14 20:08   ` Seweryn Kokot
  -- strict thread matches above, loose matches on Subject: below --
2007-05-14 10:33 Seweryn Kokot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).