find and replace with wild card

General discussions about Advanced Find and Replace
Post Reply
jcperl
Posts: 4
Joined: Thu Mar 10, 2005 12:48 pm
Location: Switzerland

find and replace with wild card

Post by jcperl »

Hello,

I have inside of a lot of files expressions like:

http://chvdms09/rs-bin/RightSite.dll/Aq ... ific=FALSE

and I have to replace them with:
http://dm/dcm/drl/objectId/CHVI-1054/ve ... el/CURRENT

CHVI-1054 remains but the part before and after in the old URL can vary !
In the new URL it's alway the same.

How can I find with a wild card like f.ex. http*CHVI because this does NOT work !!

Thank you in advance for your help.

Best regards, Jean-Claude Perlberger.

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

Bonjour Jean-Claude,

Please study in details the syntax of regular expressions:
http://www.abacre.com/afr/manual/regexpsyntax.htm

So in r.e. you should use .* instead of *
Therefore .* means any even empty char.
If there is should be at least one char between http and CHVI then
you should use .+

If you want to simply remove the left part and replace it with
http://dm/dcm/drl/objectId/
you may use the following r.e.

Search for:
http.+CHVI

Replace with:
http://dm/dcm/drl/objectId/CHVI

Now how to replace the right part?
We know that URL syntax allows using of the following chars:
a..z
A..Z
0..9
and special chars: = - & % _
In r.e. we can record this set of chars as:

[a-zA-Z0-9%\-=&_]

The right part should end up with any char that is not in the set of
URL chars (use ^ as not operator):
[^a-zA-Z0-9%\-=&_]


How finally make one regular expressions to do the job?
Suppose as you said that CHVI-1054 is constant.

The final expression will be:

Search for:
http.+CHVI-1054.+([^a-zA-Z0-9%\-=&_])

Replace with:
http://dm/dcm/drl/objectId/CHVI-1054/ve ... /CURRENT$1

I verified it perfectly works.

Note: modifier S should be OFF.

and if in fact CHVI-1054 is not constant i.e. it has:
CHVI-number format then it's also possible to program it with AFR!

A bientot
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

jcperl
Posts: 4
Joined: Thu Mar 10, 2005 12:48 pm
Location: Switzerland

Post by jcperl »

(re)bonjour,

First of all MERCI for the fast reply.

I have tried a find "http.+CHVI" but it does not work ??

I have
Modifiers M, I, G ON (checked)
Modifiers S, X OFF (unchecked)

But I saw that these Modifiers are for Batch Replace.
Does that mean that your expressions only work in this mode and NOT with the normal find ?

Cordialement, Jean-Claude Perlberger

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

Yes, you are right. I was talking about Batch replace mode.
So you should go to "Batch replace" tab and check ON "Use regular
expressions" option.

If you check "Just find" it will only find without replacements.

In future we are going to add r.e. into Find operation (tab).
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

jcperl
Posts: 4
Joined: Thu Mar 10, 2005 12:48 pm
Location: Switzerland

Post by jcperl »

THANK YOU VERY MUCH !!

It works very nicely.

I still would have a last (?) question: I don't see the function of $1 in http://dm/dcm/drl/objectId/CHVI-1054/ve ... el/CURRENT$1

I saw that $ means "end of line" but it seems I get the same results with or without it.

Best regards, Jean-Claude.

P.S.: I could also simplify my 2. replacement with:
Search for &.+=FALSE
Replace with /versionLabel/CURRENT

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre »

I was thinking to ask you: do all URL in your example end up with
FALSE string or not? If it's so then you may use the expression you
wrote.

I was not sure that all your URLs ends with FALSE. Therefore I
suggested the universal expression that works with all URLs.

In this example $1 is not the end of line, it's variable to return
value of sub-expression:
the text found in () of search for part maybe returned in $1 in replace
part.

For example if your have the text in your file:

http://chvdms09/rs-bin/RightSite.dll/Aq ... ific=FALSE Hello World

It means that after our URL we have one space
the expression ([^a-zA-Z0-9%\-=&_]) pick ups this space.
So in replace with part we have to return this space into the file.
and we can do it by using $1.

For more examples of using $1 please read the page:
http://www.abacre.net/forums/viewtopic.php?t=101
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

jcperl
Posts: 4
Joined: Thu Mar 10, 2005 12:48 pm
Location: Switzerland

Post by jcperl »

Many many THANKS !

Best regards, Jean-Claude.

Post Reply