
使用 Notepad++,我希望找到以下劃線開頭的全部大寫的所有單詞,並將它們轉換為正確的大小寫。
範例1,
Find:
DimCalendarDay_DATE
Replace with:
DimCalendarDay_Date
範例2,
Find:
DimCalendarDay_YEAR_PERIOD_DAY
Replace with:
DimCalendarDay_Year_Period_Day
實施例3,
Find:
First_Day
Replace with:
First_Day
我已經在我的 Notepad++ 搜尋廣告替換條件中輸入了以下內容:
Find what: [_]\w*[A-Z]\w*[A-Z]\w*
Replace with: \L \u \1
但是,上面的正規表示式將我找到的文字替換為空。
請指教...
答案1
- Ctrl+H
- 找什麼:
(_[A-Z])([A-Z]*)(?![A-Z])
- 用。
\u$1\L$2
- 檢查匹配大小寫
- 檢查環繞
- 檢查正規表示式
- Replace all
解釋:
(_[A-Z]) # group 1, an underscore followed by a capital
([A-Z]*) # group 2, 0 or more capitals
(?![A-Z]) # negative lookahead, make sure we haven't capital after
替代品:
\u$1 # uppercased the content of group 1 (i.e. the first letter)
\L$2 # lowercased the content of group 2 (i.e. the rest of the match)
鑑於:
DimCalendarDay_DATE
DimCalendarDay_YEAR_PERIOD_DAY
First_Day
給定範例的結果:
DimCalendarDay_Date
DimCalendarDay_Year_Period_Day
First_Day
螢幕截圖: