RE Search and replace

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Simin

RE Search and replace

Post by Simin »

Hi--is anybody there give me little insight on how to solve rather a puzzle here;)--
Thanks in advance--Cheers--Simin

Case Expression:
-------------------------
We need to first find the string "***TOP",then in every 3rd line from that string for eg: in "[&Group Title]" we need to append an index so it will look like "[&Group Title_1]"--The indexing rule takes every 3rd line from the string "***TOP" as the main title indexing and in between we have the sub indexing--

Input Text:
--------------
***TOP1
**XXX
[&Group Title]
13_xxxxx [visual aid]_to
33_xxxxx [visual aid]_from
.01_xxxxx [visual usage]_tout
[--]
***TOP2
**YYY
21_yyyyyyy [&File]
22_yyyyyyy [visual impact]_to
1_yyyyyyy [visual impact]_from


Expected Result:
-------------------------
***TOP1
**XXX
[&Group Title_1]
13_xxxxx [visual aid_1]_to
33_xxxxx [visual aid_2]_from
.01_xxxxx [visual usage_3]_tout
[--]
***TOP2
**YYY
21_yyyyyyy [&File_2]
22_yyyyyyy [visual impact_1]_to
1_yyyyyyy [visual impact_2]_from
Andreas

Re: RE Search and replace

Post by Andreas »

FInd:
***TOP1\n\(.*\)\n\(.*\)\]

Replace by
***TOP1\n\1\n\2_\i]

RegEx must be activated
simin

Re: RE Search and replace

Post by simin »

I am afraid the above trick is not working--i am getting *Invalid regular expression* error message--
Andreas

Re: RE Search and replace

Post by Andreas »

You are right.
it should be replace
\*\*\*TOP1\n\(.*\)\n\[(.*\)\]

by
***TOP1\n\1\n[\2_\i]
simin

Re: RE Search and replace

Post by simin »

thanks a mil--it is me again bugging u--this time it is giving me some *unmatched [ or (* error--is it that anything me doing is wrong????--also i just want to point you for setting the anchor we cannot use ***TOP1,because it is also changing instead we can use ***TOP as the anchor--also i think this RE doesnt take care of the second level indexing--can that be also handled in a single find replace or we have to go for a second level find replace--am i asking too much if i ask for giving little explanation of the above RE--thank in advance--Simin--
Andreas

Re: RE Search and replace

Post by Andreas »

\*\*\*TOP1\n\(.*\)\n\[\(.*\)\]

one backslash was missing.

\* finds literal *
TOP1 finds literal TOP1
\n finds linebreak
. finds any character
* finds any amount of what is to its left
.* therefore finds any amount of any characters
\(\) do not find anything, but whatever is found by the stuff within is remembered
\[ finds literal [
\] finds literal ]

Replace expression:
***TOP1\n\1\n[\2_\i]

***TOP1 puts exactly this into the text
\n puts a linebreak int the text
\1 puts whatever was found within the first \(\) into the text
[ puts a [ into the text
\2 puts whatever was found within the second \(\) into the text
] puts a ] into the text


"take care of the second level indexing": what are you talking about?
Post Reply