I'm trying to replace uppercase letters with corresponding lowercase letters using regex. So that
EarTH: 1,
MerCury: 0.2408467,
venuS: 0.61519726,
becomes
earth: 1,
mercury: 0.2408467,
venus: 0.61519726,
in Sublime Text. How can I downcase letters only in words that contain both lower and uppercase letters? So that it affects venUs
and not VENUS
.
Before searching with regex like
[A-Z]
, you should press the case sensitive button (or Alt+C) (as leemour nicely suggested to be edited in the accepted answer). Just to be clear, I'm leaving a few other examples:(\s)([a-z])
(\s
also matches new lines, i.e. "venuS" => "VenuS")$1\u$2
(\s)([A-Z])
$1\l$2
([a-z])([A-Z])
$1\l$2
(\w)([A-Z]+)
$1\L$2
\L$0
(\w)([A-Z]+)
$1\U$2
(\w+)([A-Z])
\U$1$2
(\w+)([A-Z])
\L$1$2
([A-Z])(\w+)
$1\U$2
([A-Z])(\w+)
$1\L$2
([a-z\s])([A-Z])(\w)
$1\l$2\u$3
(\w)([A-Z])([a-z\s])
\u$1\l$2$3
Regarding the question (match words with at least one uppercase and one lowercase letter and make them lowercase), leemour's comment-answer is the right answer. Just to clarify, if there is only one group to replace, you can just use
?:
in the inner groups (i.e. non capture groups) or avoid creating them at all:((?:[a-z][A-Z]+)|(?:[A-Z]+[a-z]))
OR([a-z][A-Z]+|[A-Z]+[a-z])
\L$1
2016-06-23 Edit
Tyler suggested by editing this answer an alternate find expression for #4:
(\B)([A-Z]+)
According to the documentation,
\B
will look for a character that is not at the word's boundary (i.e. not at the beginning and not at the end). You can use the Replace All button and it does the exact same thing as if you had(\w)([A-Z]+)
as the find expression.However, the downside of
\B
is that it does not allow single replacements, perhaps due to the find's "not boundary" restriction (please do edit this if you know the exact reason).You may:
Find:
(\w)
Replace With:\L$1
Or select the text, ctrl+K+L.
In BBEdit works this (ex.: changing the ID values to lowercase):
Search any value:
<a id="(?P<x>.*?)"></a>
Replace with the same in lowercase:<a id="\L\P<x>\E"></a>
Was:
<a id="VALUE"></a>
Became:<a id="value"></a>
Try this
([A-Z])([A-Z]+)\b
$1\L$2
Make sure case sensitivity is on (Alt + C)
I figured this might come in handy for others as well :
find:
([A-Z])(.*)
replace:
\L$1$2
--> will convert all letters in$1
and$2
to lowercaseBUT
\l$1$2
--> will only convert the first letter of$1
to lowercase and leave everything else as isThe same goes for uppercase with
\U
and\u
Regular expression
Find:
\w+
Replace:
\L$0
\L
Converts everything up to lowercase$0
Capture groups