Another help: conditional replace.
-
Goodnight.
I need other technical help (support).
There are two conversion operations.
But for a single letter, after the apostrophe, parentheses or cuotas
One from lowercase to uppercase, for use… with names .
Another, from uppercase to lowercase, to use… with the name of the song .example for up (before -> after):
D’ammare -> D’Amare
John’mary -> John’Mary
John, (the) Legend -> John, (The) Legend
Paul, “the” Man -> Paul, “The” Manexample for down (before -> after)
Can’T -> Can’t
I’M -> I’mThanks.
-
@João-Borloth said in Another help: conditional replace.:
I need other technical help (support).
There are two conversion operations.I’ve been trying to integrate both regexes into one and I know it is possible, but currently I will offer up two. One changes the situation like D’ammare into D’Ammare. The second regex will do the Can’T change into Can’t.
Not sure if you can understand regexes, if not and want to understand better let us know. In the meantime I will continue to try and achieve a single regex to do both steps as I believe it is more efficient.
Lower case to upper case
Find What:([\w ][[:punct:]])(\w)(?=\w)
Replace With:${1}\u${2}
Upper case to lower case
Find What:1([\w ][[:punct:]])(\w)(?=\b)
Replace With:${1}\l${2}
Terry
-
@Terry-R said in Another help: conditional replace.:
I’ve been trying to integrate both regexes into one and I know it is possible
@João-Borloth
It took only a few more moments to figure out my mistake. I had lost count of the groups and was referencing the wrong ones (bit of a rookie mistake actually).So here is the combined regex:
Find What:([\w ][[:punct:]])(?:(\w(?=\w))|(\w(?=\b)))
Replace With:${1}(?2\u${2})(?3\l${3})
Now this looks a bit more complicated, again if you wish more description it can be given.
Terry
PS, just saw @PeterJones response below. Agreed it could be considered better separate, except I figured these were both operating on the same set of data. I haven’t tested against “all” different scenarios. Not sure I could list them all. Interesting about the lookahead with the boundary. I see where you are coming from and I suppose I had blinkers on at the time. Maybe I might consider looking into this further with an idea to encompass “all” possible scenarios. Of course the requester could come back with other stuff that it didn’t work on. I think the
(a)
will be one such problem area. -
@Terry-R ,
Good first attempt. I’m not sure it really needs to be combined. They are conceptually two different actions, and running them separately makes more sense IMO.
However, the original problem, as stated, is not going to work in the generic sense.
I would'Ve thought that "V" should also be lowercased. They couldn'T'Ve imagined the can of worms they asked to be opened
. Not all contractions are single-letter-after-apostrophe; there are even cascaded contractions allowed in English. And what about"My Country 'Tis of Thee". 'Tis the start of a new sentence, and this 'tis not, so they require different capitalization
? Good luck. So my point to the original poster: every time you come up with something that you hope is the “complete” set of rules for processing something in English, the chances are that some text you try to change in the future will find an exception to those rules. Having One Regex To Rule Them All is never really going to work.And just a technical note for @Terry-R :
(?=\b)
: the\b
assertion is already 0-width, so you don’t need to wrap it in a lookahead. -
Hello, @joão-borloth, @terry-r and All,
Your goal should be reached with these two regexes S/R, below, which are alternate solutions to the @terry-r’s ones !
-
For Uppercase changes :
-
SEARCH
(?-i)(?<=\W)(?!^)\l
-
REPLACE
\u$0
-
-
For Lowercase changes :
-
SEARCH
(?-i)(?<=\W)(?!^)\u
-
REPLACE
\l$0
-
IMPORTANT note : These two regex S/R do NOT change any
accentuated
characters !!Best Regards,
guy038
-
-
Hi, @joão-borloth, @terry-r and All,
Terry, you shoudn’t have upvoted my post, because using the
(?<=\W)
allows to change an upper letter, after aspace
char, which should not happen !So, your use of the Posix class
[[:punct:]]
is the right one !Here is my new version where I gathered the two cases :
-
SEARCH
(?-i)(?<=[[:punct:]])(?:(\l)|\u)
-
REPLACE
(?1\u:\l)$0
@joão-borloth, if you prefer to use each regex S/R, independently :
-
SEARCH
(?-i)(?<=[[:punct:]])\l
-
REPLACE
\u$0
and
-
SEARCH
(?-i)(?<=[[:punct:]])\u
-
REPLACE
\l$0
BR
guy038
-
-
Thanks for all.