Topic: Question about {Search Replace} commnad. (1 of 5), Read 81 times
Conf: Search and Replace
From: Peter Rejto
Date: Monday, March 01, 2004 08:04 PM

Hello,

I have a subtle question about the Search, Replace menu
command.
I would like to renumber my {eq:2.1} to {eq:2.2} but keep say,
{eq:2.11} unchanged. As per the online help on regexp search
I entered the search string
eq:2.1[~0-9] and the replacement string eq:2.2.

My problem is that in the process I lost a curly brace, "}", and
my Latex was complaining quite a bit.

I did find a work around: Use the Replace macro, mark the
beginning. However, instead of marking the end of the string,
come back one character with the Char(-1) macro. Then mark
the block and replace the marked block.

I thought there should be an easier way of doing it.

It is not a major issue. But I thought, I ask it.

Thanks,

-peter.

 


Topic: Question about {Search Replace} commnad. (2 of 5), Read 84 times
Conf: Search and Replace
From: Christian Ziemski
Date: Tuesday, March 02, 2004 02:22 AM

On 3/1/2004 8:04:06 PM, Peter Rejto wrote:

>I have a subtle question about the Search, Replace menu command.
>I would like to renumber my {eq:2.1} to {eq:2.2} but keep
>say, {eq:2.11} unchanged.
>
>I entered the search string eq:2.1[~0-9] and the
>replacement string eq:2.2.
>
>My problem is that in the process I lost a curly brace, "}"

The curly brace is matched by your expression "[~0-9]" and replaced by nothing. So it's lost...


A simple approach is to (regexp) search for "2.1\}".
But that is a bit inflexible.

A more flexible regular expression could be:

Search: 2.1{[^0-9]}
Replace: 2.2\1

The expression {[^0-9]} matches the first non-digit (like you already did), but stores it internally as group #1.
So you can reference it with "\1" in the replacement string.

Christian

 


Topic: Question about {Search Replace} commnad. (3 of 5), Read 87 times
Conf: Search and Replace
From: Pauli Lindgren
Date: Tuesday, March 02, 2004 05:05 AM

On 3/2/2004 2:22:15 AM, Christian Ziemski wrote:
>On 3/1/2004 8:04:06 PM, Peter Rejto wrote:
>
>>I would like to renumber my {eq:2.1} to {eq:2.2} but keep
>>say, {eq:2.11} unchanged.
>
>A more flexible regular expression could
>be:
>
> Search: 2.1{[^0-9]}
> Replace: 2.2\1

What you need the regular expressions for?
Why not just write "{eq:2.1}" in the Search box and
"{eq:2.2}" in the Replace box (without the quotes)?

--
Pauli

 


Topic: Question about {Search Replace} commnad. (4 of 5), Read 89 times
Conf: Search and Replace
From: Christian Ziemski
Date: Tuesday, March 02, 2004 08:13 AM

On 3/2/2004 5:05:24 AM, Pauli Lindgren wrote:

>What you need the regular expressions for?
>Why not just write "{eq:2.1}" in the Search box and
>"{eq:2.2}" in the Replace box (without the quotes)?

You are correct.
Regular expressions are not needed in this special case.

But Peter used them and so I followed.
And I tried to show the very powerful grouping feature of regexp.

Christian

 


Topic: Question about {Search Replace} commnad. (5 of 5), Read 87 times
Conf: Search and Replace
From: Peter Rejto
Date: Tuesday, March 02, 2004 09:11 AM

On 3/2/2004 2:22:15 AM, Christian Ziemski wrote:
>On 3/1/2004 8:04:06 PM, Peter Rejto
>wrote:
>
>
>A simple approach is to (regexp) search
>for "2.1\}".
>But that is a bit inflexible.
>
>A more flexible regular expression could
>be:
>
> Search: 2.1{[^0-9]}
> Replace: 2.2\1
>
>The expression {[^0-9]} matches the
>first non-digit (like you already did),
>but stores it internally as group #1.
>So you can reference it with "\1" in the
>replacement string.

Thanks,

Christian. This is exactly what I missed!

Thanks Pauli,

Now why do I use regular expressions? I have a macro which I use to renumber my equations and this macro uses regular expressions. My previous question was motivated by a rather special case of that macro.


Regular expressions seem to work for me in my macro. In the old days they used to say, "don't change horses midstream".
I adapted it to mean, "don't change notations midstream".

This is not to say that it could not be done simpler using pattern search! Incidentally, how would I program,

replace 2.n by 2.n+1 for n=0,1,2,3,4,5,6,7,8,9.



Thanks again gentlemen,

-peter.