replace low cap with upper case at position

A swapping-ground for Regular Expression syntax

replace low cap with upper case at position

Postby naltar » Wed Jun 16, 2021 9:47 am

Hello,

I'm trying to replace low cap letters, with equivalent upper case letters, e.g.
from:
P37-S34-c__nn4gqsz
to:
P37-S34-C__nn4gqsz

Letters to replace range from 'a' to 'i', always at the same position (9), but I don't think it matters, in the sense that it would be useful to replace _any_low cap letter with upper case at _any_ specific position.
There was a similar topic 10 years ago (replace character at definite position), but the replacement was with a specific character, rather than upper case of the same letter.
Actually a similar (or identical) question did surface on the forum, but the solution (that works) required javascript and commercial license:
viewtopic.php?f=11&t=3884&p=10045&hilit=20th#p10045

I also looked at solutions in the forum to insert certain characters at exact position, but no, it doesn't get me any closer to removing a variable low cap with equivalent upper cap. And when I looked for regex 'inspiration' on notepad++ forum and saw solutions for replacing low caps with uppercase in certain situations, I felt rather wobbly around the knees...

Regards,
n.
naltar
 
Posts: 3
Joined: Sun Dec 27, 2015 6:23 pm

Re: replace low cap with upper case at position

Postby naltar » Wed Jun 16, 2021 2:14 pm

... and to reply to my own post, Case (4) title does the job. Yes, it also capitalizes "nn4gqsz" into "Nn4gqsz", but this can be easily fixed with replace / with (Match case), as the 'nn' bit of a string is fairly unique. Of course, until I stumble upon a file with double 'nn' inside w word. But that would hopefully not be in the title format...
Anyway, I would still very much like to know how to replace lower case at specific position with upper case, because it would be useful in... other scenarios.

Regards,
n.
naltar
 
Posts: 3
Joined: Sun Dec 27, 2015 6:23 pm

Re: replace low cap with upper case at position

Postby Luuk » Wed Jun 16, 2021 2:29 pm

There was a good post for conducting uppercase with many of the different options, but now Im not finding it anywhere!
So this some ways to conduct uppercase with RegEx(1), first putting a checkmark in "v2", then using Match and Replace like ...

Uppercase any 9th-letter ...
^(.{8})(.)
\1\U\2

Uppercase the 9th-letter, if its 'a-i' ...
^(.{8})([a-i])
\1\U\2

Uppercase the 9th-letter, if its 'a-i', comes right after P##-S##-, and just before two underscores ...
^(P\d\d-S\d\d-)([a-i]__)
\1\U\2

This one is just like above, but only cares about "1-or-more numbers" after the 'P' and the 'S' ...
^(P\d+-S\d+-)([a-i]__)
\1\U\2
So it would also uppercase 'a-i' inside of names starting like... P1-S123456789-c__
Luuk
 
Posts: 320
Joined: Fri Feb 21, 2020 10:58 pm


Return to Regular Expressions