Page 1 of 1

find and replace with wild card

Posted: Mon Mar 14, 2005 12:43 pm
by jcperl

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.

Posted: Mon Mar 14, 2005 2:01 pm
by Abacre
Bonjour Jean-Claude,

Please study in details the syntax of regular expressions:

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
you may use the following r.e.

Search for:

Replace with:

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


The right part should end up with any char that is not in the set of
URL chars (use ^ as not operator):

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:

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

Posted: Mon Mar 14, 2005 2:22 pm
by jcperl

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

Posted: Mon Mar 14, 2005 2:26 pm
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).

Posted: Tue Mar 15, 2005 9:42 am
by jcperl

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

Posted: Tue Mar 15, 2005 11:28 am
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

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

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:

Posted: Tue Mar 15, 2005 11:45 am
by jcperl
Many many THANKS !

Best regards, Jean-Claude.