Hello, @joão-borloth, @peterjones, @coises and All,
@joão-borloth, here is my contribution to your problem ! I assume these following statements :
Regarding the searched expression :
The entire searched expression begins and ends each line and contains, at least, three characters
The searched expression begins with two letter characters and ends with a letter character
The characters of the searched expression, from the third one to the last but one, may be any char
Regarding the replacement expression :
The replacement expression contains, at least, two characters
The replacement expression begins with a letter character and ends with a letter character
The characters of the replacement expression, from the second one to the last but one, may be any char
Regarding the case rules :
The case of the first letter of the replacement expression will be the same as the case of the first letter of the searched expression
The case of the last letter of the replacement expression will be the same as the case of the last letter of the searched expression
The case of the all other characters of the replacement expression will be the same as the case of the second letter of the searched expression
First, giving your general template :
Screw
SCREW
screw
ScreW
sCREW
I created the same template for two other expressions :
Test
TEST
test
TesT
tEST
Wonderful time
WONDERFUL TIME
wonderful time
Wonderful timE
wONDERFUL TIME
And using the following regex S/R :
SEARCH (?-is)^(?:(\u)|\l)(?:(\u)|\l).*(?:(\u)|\l)$
REPLACE (?1N:n)(?2AI:ai)(?3L:l)
I did get the 3 identical blocks, containing the word nail , below :
Nail
NAIL
nail
NaiL
nAIL
Nail
NAIL
nail
NaiL
nAIL
Nail
NAIL
nail
NaiL
nAIL
So, now, the next problem ( which, indeed, is rather the initial problem ! ) is how to get the replacement text, whatever the text used ?
Again, we’ll use a regex replacement :
SEARCH (?-s)^(.)(.*)(.)$
REPLACE \(\?1\u\1:\l\1\)\(\?2\U\2\E:\L\2\E\)\(\?3\u\3:\l\3\)
For example, given all case syntaxes of the word nail :
nail
naiL
naIl
naIL
Nail
NaiL
NaIl
NaIL
nAil
nAiL
nAIl
nAIL
NAil
NAiL
NAIl
NAIL
You can verify that we always get the same correct result, below :
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
(?1N:n)(?2AI:ai)(?3L:l)
IF, we extend the use of this regex S/R to other expressions, whatever their case, it does give correct results ! For instance, given this short list, below :
naiL
WINDOW
An imPRESSive caSTLe
bIg
Az
We correctly get this OUTPUT :
(?1N:n)(?2AI:ai)(?3L:l)
(?1W:w)(?2INDO:indo)(?3W:w)
(?1A:a)(?2N IMPRESSIVE CASTL:n impressive castl)(?3E:e)
(?1B:b)(?2I:i)(?3G:g)
(?1A:a)(?2:)(?3Z:z)
So, the procedure is :
First, given a specific word, which will be the replacement expression, you’ll find the true replacement regex syntax with :
SEARCH (?-s)^(.)(.*)(.)$
REPLACE \(\?1\u\1:\l\1\)\(\?2\U\2\E:\L\2\E\)\(\?3\u\3:\l\3\)
Secondly, with the following regex S/R :
SEARCH (?-is)^(?:(\u)|\l)(?:(\u)|\l).*(?:(\u)|\l)$
REPLACE : The result of the PREVIOUS regex S/R
It would replace any expression with the replacement expression, using our specific case rules !
Two examples :
Expression to change : Screw and expression to replace An impressive castle. Thus :
SEARCH (?-is)^(?:(\u)|\l)(?:(\u)|\l).*(?:(\u)|\l)$
REPLACE (?1A:a)(?2N IMPRESSIVE CASTL:n impressive castl)(?3E:e)
So, from this INPUT text :
Screw
SCREW
screw
ScreW
sCREW
We would get this OUTPUT :
An impressive castle
AN IMPRESSIVE CASTLE
an impressive castle
An impressive castlE
aN IMPRESSIVE CASTLE
Expression to change : Wonderful time and expression to replace Az. Thus :
SEARCH (?-is)^(?:(\u)|\l)(?:(\u)|\l).*(?:(\u)|\l)$
REPLACE (?1A:a)(?2:)(?3Z:z)
So, from this INPUT text :
Wonderful time
WONDERFUL TIME
wonderful time
Wonderful timE
wONDERFUL TIME
we would get this OUTPUT text :
Az
AZ
az
AZ
aZ
Best Regards,
guy038