* 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
* Re: replace regexp question
[not found] <mailman.634.1179145690.32220.help-gnu-emacs@gnu.org>
@ 2007-05-14 19:00 ` Ralf Angeli
2007-05-14 20:08 ` Seweryn Kokot
0 siblings, 1 reply; 9+ messages in thread
From: Ralf Angeli @ 2007-05-14 19:00 UTC (permalink / raw)
To: help-gnu-emacs
* Seweryn Kokot (2007-05-14) writes:
> 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?
Call `indent-according-to-mode' on those lines after the insertion.
--
Ralf
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: replace regexp question
2007-05-14 19:00 ` Ralf Angeli
@ 2007-05-14 20:08 ` Seweryn Kokot
0 siblings, 0 replies; 9+ messages in thread
From: Seweryn Kokot @ 2007-05-14 20:08 UTC (permalink / raw)
To: help-gnu-emacs
Ralf Angeli <dev.null@caeruleus.net> writes:
> * Seweryn Kokot (2007-05-14) writes:
>
>> 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?
>
> Call `indent-according-to-mode' on those lines after the insertion.
thanks, solved.
Seweryn
^ permalink raw reply [flat|nested] 9+ messages in thread
* 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
* Re: Replace regexp question
2013-06-08 6:11 Replace " Leandro Marcolino
@ 2013-06-08 12:39 ` Andreas Röhler
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Röhler @ 2013-06-08 12:39 UTC (permalink / raw)
To: help-gnu-emacs
Am 08.06.2013 08:11, schrieb Leandro Marcolino:
> 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?..
>
\(a+\)
Cheers,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Replace regexp question
[not found] <mailman.1206.1370689126.22516.help-gnu-emacs@gnu.org>
@ 2013-06-08 12:41 ` Pascal J. Bourguignon
2013-06-08 16:44 ` Leandro Marcolino
0 siblings, 1 reply; 9+ messages in thread
From: Pascal J. Bourguignon @ 2013-06-08 12:41 UTC (permalink / raw)
To: help-gnu-emacs
Leandro Marcolino <leandromarcolino@gmail.com> writes:
> 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?..
That's because there is a single a inside \( \)!
Try: \(a+\) -> \1b
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
You can take the lisper out of the lisp job, but you can't take the lisp out
of the lisper (; -- antifuchs
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Replace regexp question
2013-06-08 12:41 ` Pascal J. Bourguignon
@ 2013-06-08 16:44 ` Leandro Marcolino
2013-06-08 16:46 ` Leandro Marcolino
0 siblings, 1 reply; 9+ messages in thread
From: Leandro Marcolino @ 2013-06-08 16:44 UTC (permalink / raw)
To: help-gnu-emacs
Thank you very much for all the replies!.. :) But, maybe my example was too
simplistic.... hehe
I want to file occurrences of "<span lang=ZH-CN
>私私私</span><span lang=PT-BR", but the number of
私 can be one or more, and replae by "<span lang=ZH-CN
style='letter-spacing:-5px'>私私私</span><span
lang=PT-BR".
If I try: "<span lang=ZH-CN >\(私+\)</span><span lang=PT-BR -> <span
lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR" then no
pattern is found
If I try: "<span lang=ZH-CN >\(私\)+</span><span lang=PT-BR -> <span
lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR" then the
sequence of 私 changes to a single 私.
Is there a way to solve this problem?...
Thank you very much!..
Thanks,
Leandro
On Sat, Jun 8, 2013 at 8:11 AM, Pascal J. Bourguignon [via Emacs] <
ml-node+s1067599n288199h15@n5.nabble.com> wrote:
> Leandro Marcolino <[hidden email]<http://user/SendEmail.jtp?type=node&node=288199&i=0>>
> writes:
>
> > 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?..
>
> That's because there is a single a inside \( \)!
> Try: \(a+\) -> \1b
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> A bad day in () is better than a good day in {}.
> You can take the lisper out of the lisp job, but you can't take the lisp
> out
> of the lisper (; -- antifuchs
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://emacs.1067599.n5.nabble.com/Replace-regexp-question-tp288179p288199.html
> To unsubscribe from Replace regexp question, click here<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=288179&code=bGVhbmRyb21hcmNvbGlub0BnbWFpbC5jb218Mjg4MTc5fC0xNDQxMDQ2NDk4>
> .
> NAML<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Replace regexp question
2013-06-08 16:44 ` Leandro Marcolino
@ 2013-06-08 16:46 ` Leandro Marcolino
2013-06-08 17:27 ` Leandro Marcolino
0 siblings, 1 reply; 9+ messages in thread
From: Leandro Marcolino @ 2013-06-08 16:46 UTC (permalink / raw)
To: help-gnu-emacs
Just to be clear, when I say replace by: "<span lang=ZH-CN
style='letter-spacing:-5px'>私私私</span><span
lang=PT-BR", I mean that the number of 私 must be the same as in the
original text.
Thanks!..
Leandro
On Sat, Jun 8, 2013 at 9:44 AM, Leandro Marcolino <
leandromarcolino@gmail.com> wrote:
> Thank you very much for all the replies!.. :) But, maybe my example was
> too simplistic.... hehe
>
> I want to file occurrences of "<span lang=ZH-CN
> >私私私</span><span lang=PT-BR", but the number of
> 私 can be one or more, and replae by "<span lang=ZH-CN
> style='letter-spacing:-5px'>私私私</span><span
> lang=PT-BR".
>
> If I try: "<span lang=ZH-CN >\(私+\)</span><span lang=PT-BR -> <span
> lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR" then no
> pattern is found
> If I try: "<span lang=ZH-CN >\(私\)+</span><span lang=PT-BR -> <span
> lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR" then the
> sequence of 私 changes to a single 私.
>
> Is there a way to solve this problem?...
>
> Thank you very much!..
>
> Thanks,
> Leandro
>
>
> On Sat, Jun 8, 2013 at 8:11 AM, Pascal J. Bourguignon [via Emacs] <
> ml-node+s1067599n288199h15@n5.nabble.com> wrote:
>
>> Leandro Marcolino <[hidden email]<http://user/SendEmail.jtp?type=node&node=288199&i=0>>
>> writes:
>>
>> > 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?..
>>
>> That's because there is a single a inside \( \)!
>> Try: \(a+\) -> \1b
>>
>> --
>> __Pascal Bourguignon__ http://www.informatimago.com/
>> A bad day in () is better than a good day in {}.
>> You can take the lisper out of the lisp job, but you can't take the lisp
>> out
>> of the lisper (; -- antifuchs
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://emacs.1067599.n5.nabble.com/Replace-regexp-question-tp288179p288199.html
>> To unsubscribe from Replace regexp question, click here<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=288179&code=bGVhbmRyb21hcmNvbGlub0BnbWFpbC5jb218Mjg4MTc5fC0xNDQxMDQ2NDk4>
>> .
>> NAML<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Replace regexp question
2013-06-08 16:46 ` Leandro Marcolino
@ 2013-06-08 17:27 ` Leandro Marcolino
0 siblings, 0 replies; 9+ messages in thread
From: Leandro Marcolino @ 2013-06-08 17:27 UTC (permalink / raw)
To: help-gnu-emacs
Oh, I think I got it. I nested the groups like: "<span lang=ZH-CN
>\(\(私\)+\)</span><span lang=PT-BR -> <span lang=ZH-CN
style='letter-spacing:-5px'>\1</span><span lang=PT-BR". That works!.. :)
Thanks!..
Leandro
On Sat, Jun 8, 2013 at 9:46 AM, Leandro Marcolino <
leandromarcolino@gmail.com> wrote:
> Just to be clear, when I say replace by: "<span lang=ZH-CN
> style='letter-spacing:-5px'>私私私</span><span
> lang=PT-BR", I mean that the number of 私 must be the same as in
> the original text.
>
> Thanks!..
>
> Leandro
>
>
> On Sat, Jun 8, 2013 at 9:44 AM, Leandro Marcolino <
> leandromarcolino@gmail.com> wrote:
>
>> Thank you very much for all the replies!.. :) But, maybe my example was
>> too simplistic.... hehe
>>
>> I want to file occurrences of "<span lang=ZH-CN
>> >私私私</span><span lang=PT-BR", but the number of
>> 私 can be one or more, and replae by "<span lang=ZH-CN
>> style='letter-spacing:-5px'>私私私</span><span
>> lang=PT-BR".
>>
>> If I try: "<span lang=ZH-CN >\(私+\)</span><span lang=PT-BR ->
>> <span lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR"
>> then no pattern is found
>> If I try: "<span lang=ZH-CN >\(私\)+</span><span lang=PT-BR ->
>> <span lang=ZH-CN style='letter-spacing:-5px'>\1</span><span lang=PT-BR"
>> then the sequence of 私 changes to a single 私.
>>
>> Is there a way to solve this problem?...
>>
>> Thank you very much!..
>>
>> Thanks,
>> Leandro
>>
>>
>> On Sat, Jun 8, 2013 at 8:11 AM, Pascal J. Bourguignon [via Emacs] <
>> ml-node+s1067599n288199h15@n5.nabble.com> wrote:
>>
>>> Leandro Marcolino <[hidden email]<http://user/SendEmail.jtp?type=node&node=288199&i=0>>
>>> writes:
>>>
>>> > 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?..
>>>
>>> That's because there is a single a inside \( \)!
>>> Try: \(a+\) -> \1b
>>>
>>> --
>>> __Pascal Bourguignon__ http://www.informatimago.com/
>>> A bad day in () is better than a good day in {}.
>>> You can take the lisper out of the lisp job, but you can't take the lisp
>>> out
>>> of the lisper (; -- antifuchs
>>>
>>>
>>> ------------------------------
>>> If you reply to this email, your message will be added to the
>>> discussion below:
>>>
>>> http://emacs.1067599.n5.nabble.com/Replace-regexp-question-tp288179p288199.html
>>> To unsubscribe from Replace regexp question, click here<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=288179&code=bGVhbmRyb21hcmNvbGlub0BnbWFpbC5jb218Mjg4MTc5fC0xNDQxMDQ2NDk4>
>>> .
>>> NAML<http://emacs.1067599.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>
>>
>
^ 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 --
2007-05-14 10:33 replace regexp question Seweryn Kokot
[not found] <mailman.634.1179145690.32220.help-gnu-emacs@gnu.org>
2007-05-14 19:00 ` Ralf Angeli
2007-05-14 20:08 ` Seweryn Kokot
-- strict thread matches above, loose matches on Subject: below --
2013-06-08 6:11 Replace " Leandro Marcolino
2013-06-08 12:39 ` Andreas Röhler
[not found] <mailman.1206.1370689126.22516.help-gnu-emacs@gnu.org>
2013-06-08 12:41 ` Pascal J. Bourguignon
2013-06-08 16:44 ` Leandro Marcolino
2013-06-08 16:46 ` Leandro Marcolino
2013-06-08 17:27 ` Leandro Marcolino
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).