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.
find and replace with wild card
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
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
(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
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
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
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
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
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