IT

정규식은 대문자를 소문자로 바꿉니다.

lottoking 2020. 5. 15. 08:26
반응형

정규식은 대문자를 소문자로 바꿉니다.


정규식을 사용하여 대문자를 해당 소문자로 바꾸려고합니다. 그래서

EarTH:   1,
MerCury: 0.2408467,
venuS:   0.61519726,

된다

earth:   1,
mercury: 0.2408467,
venus:   0.61519726,

숭고한 텍스트. 소문자와 대문자를 모두 포함하는 단어에서만 문자를 소문자로 바꿀 수 있습니까? 그래서 그것은 영향을 미치지 venUs않습니다 VENUS.


당신은 할 수있다:

찾기 : (\w)바꾸기 :\L$1

또는 ctrl+ K+ 텍스트를 선택하십시오 L.


나는 이것이 다른 사람들에게도 유용 할 것이라고 생각했다.

찾기:

  • ([A-Z])(.*)

바꾸다:

  • \L$1$2-> 모든 문자를 변환합니다 $1$2소문자로
    하지만
  • \l$1$2->의 첫 글자 만 $1소문자로 변환하고 나머지는 그대로 둡니다.

동일은 대문자 간다 \U하고\u


같은 정규 표현식으로 검색하기 전에 [A-Z], 당신이해야 하는 경우 민감한 버튼을 누르면 (또는 Alt+ C(로) leemour 정중하게 제안 허용 대답에서 편집 할). 분명히하기 위해 몇 가지 다른 예를 남겨두고 있습니다.

  1. 단어를 대문자
    • 찾기 : (\s)([a-z])( \s"venuS"=> "VenuS"와 같이 새 줄과도 일치)
    • 바꾸다: $1\u$2
  2. 대문자를 사용하지 않습니다
    • 찾기: (\s)([A-Z])
    • 바꾸다: $1\l$2
  3. 낙타 케이스 제거 (예 : cAmelCAse => camelcAse => camelcase)
    • 찾기: ([a-z])([A-Z])
    • 바꾸다: $1\l$2
  4. 단어 내 소문자 (예 : LowerCASe => 소문자)
    • 찾기: (\w)([A-Z]+)
    • 바꾸다:

      $1\L$2
    • 대체 교체 : \L$0
  5. 단어 내 대문자 (예 : upperCASe => uPPERCASE)
    • 찾기: (\w)([A-Z]+)
    • 바꾸다: $1\U$2
  6. 대문자 이전 (예 : upperCase => 대문자)
    • 찾기: (\w+)([A-Z])
    • 바꾸다: \U$1$2
  7. 이전 소문자 (예 : LOWERCase => 소문자)
    • 찾기: (\w+)([A-Z])
    • 바꾸다: \L$1$2
  8. 나머지 대문자 (예 : upperCase => upperCASE)
    • 찾기: ([A-Z])(\w+)
    • 바꾸다: $1\U$2
  9. 나머지는 소문자로 입력하십시오 (예 : lOWERCASE => lO 소문자).
    • 찾기: ([A-Z])(\w+)
    • 바꾸다: $1\L$2
  10. Shift- 오른쪽 대문자 (예 : Case => cAse => caSe => casE)
    • 찾기: ([a-z\s])([A-Z])(\w)
    • 바꾸다: $1\l$2\u$3
  11. Shift- 왼쪽 대문자 (예 : CasE => CaSe => CAse => Case)
    • 찾기: (\w)([A-Z])([a-z\s])
    • 바꾸다: \u$1\l$2$3

질문과 관련하여 ( 대소 문자가 하나 이상 소문자와 일치 하고 소문자가되도록) leemour의 의견-답변정답 입니다. 명확히하기 위해 교체 할 그룹이 하나 뿐인 경우 ?:내부 그룹 (예 : 비 캡처 그룹 )에서 사용하거나 전혀 생성하지 않아도 됩니다.

  • Find: ((?:[a-z][A-Z]+)|(?:[A-Z]+[a-z])) OR ([a-z][A-Z]+|[A-Z]+[a-z])
  • Replace: \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).


Regular expression

Find:\w+

Replace:\L$0

Sublime Text uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library to power regular expressions in search panels.

\L Converts everything up to lowercase

$0 Capture groups


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

  • Find: ([A-Z])([A-Z]+)\b
  • Replace: $1\L$2

Make sure case sensitivity is on (Alt + C)

참고URL : https://stackoverflow.com/questions/20742076/regex-replace-uppercase-with-lowercase-letters

반응형