• Login
Community
  • Login

Convert Case to ...

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 8 Posters 32.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    Jeronymite
    last edited by Jul 12, 2015, 1:10 AM

    It’s great to have the Convert Case to capability. Can it be enhanced to include more options? For example, the TitleCase Addon for Mozilla Thunderbird has these options:

    • tOGGLE cASE
    • Proper case
    • Title Case
    • Title Case (CamelCase)
    • Start Case
    • Start Case (CamelCase)
    • CamelCase
    • UPPER CASE
    • lower case

    Thanks!

    1 Reply Last reply Reply Quote 0
    • E
      evanslove
      last edited by Aug 24, 2015, 8:06 PM

      This would be an absolutely wonderful addition! I would do it myself if i knew how…

      1 Reply Last reply Reply Quote 0
      • R
        Ricardo
        last edited by Aug 25, 2015, 4:57 AM

        Install TextFX plugin, it’s one of the best plugins.

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by guy038 Sep 12, 2023, 9:40 AM Aug 31, 2015, 9:28 PM

          Hello Jeronymite and All,

          UPDATED on 12/02/2016 ( addition of the syntax (?-is), in front of each regex, to ensure that :

          • The search is performed in a sensitive way

          • The dot meta-character matches standard characters, only

          I did some investigations, on the Net, about the different Capitalization rules. Below, 3 links to interesting articles on that topic :

          http://c2.com/cgi/wiki?CapitalizationRules

          https://en.wikipedia.org/wiki/Letter_case

          http://www.titlecase.com/


          From that documentation, here is, below, a ( non exhaustive !) summary of the main kinds of capitalisation :

          • UPPERCASE / All-caps THE MAPS AND A BOOK ARE IN MY BROWN FRENCH BAG. --> All letters are UPPERCASE

          • Start Case / Proper Case The Maps And A Book Are In My Brown French Bag. --> All words are Capitalized, regardless its category

          • tOGGLE cASE ( from ABOVE ) tHE mAPS aND a bOOK aRE iN mY bROWN fRENCH bAG. --> INVERT the case of each letter

          • Title Case The Maps and a Book Are in My Brown French Bag. --> FIRST word Capitalized, and all other words, except for articles, prepositions and conjunctions

          • Title Case, Variant 1 The Maps and a Book are in My Brown French Bag. --> As Title Case and excepting the forms of “to be”

          • Title Case, Variant 2 The Maps and a Book are in my Brown French Bag. --> As Title Case but except for all closed-class words

          • German Sentence Case The Maps and a Book are in my brown French Bag. --> FIRST word and all NOUNS are Capitalized

          • german mid Sentence Case the Maps and a Book are in my brown French Bag. --> All NOUNS are Capitalized, except for the FIRST word

          • Sentence case The maps and a book are in my brown French bag. --> FIRST word, Proper nouns and some specific words ( as the pronoun I ) are Capitalized

          • mid sentence case the maps and a book are in my brown French bag. --> As above, but FIRST word is NOT Capitalized

          • lowercase the maps and a book are in my brown french bag. --> All letters are lowercase

          • SCREAMING_SNAKE_CASE THE_MAPS_AND_A_BOOK_ARE_IN_MY_BROWN_FRENCH_BAG_ --> All letters are UPPERCASE, and words separated by underscores

          • snake_case [T/t]he_maps_and_a_book_are_in_my_brown_french_bag_ --> All letters, from the second, lowercase, and words separated by underscores

          • KEBAB-CASE THE-MAPS-AND-A-BOOK-ARE-IN-MY-BROWN-FRENCH-BAG- --> All letters UPPERCASE, and words separated by hyphens

          • Train-Case The-Maps-And-A-Book-Are-In-My-Brown-French-Bag- --> All words are Capitalized and separated by hyphens

          • kebab-case [T/t]he-maps-and-a-book-are-in-my-brown-french-bag- --> All letters, from the second, lowercase, and words separated by hyphens

          • PascalCase TheMapsAndABookAreInMyBrownFrenchBag --> All words, with letters only, are Capitalized and run together

          • [Upper]CamelCase / WikiCase TheMapsAndBookAreInMyBrownFrenchBag --> As PascalCase, but each UPPERCASE letter must be followed by a lowercase letter ( So, initial ONE LETTER words are DELETED )

          • lowerCamelCase theMapsAndBookAreInMyBrownFrenchBag --> As WikiCase, except the FIRST word is lowercase

          • StUdLyCaPs ThEmApSaNdAbOoKaReInMyBrOwNfReNcHbAg --> UPPER and lower letters alternated, beginning UPPERCASE

          • StUdLyCaPs, Variant 1 tHeMaPsAnDaBoOkArEiNmYbRoWnFrEnChBaG --> UPPER and lower letters alternated, beginning lowercase

          • StUdLyCaPs, Variant 2 thEmApsAndAbOOkArEInmYbrOwnfrEnchbAg --> VOWELS are UPPERCASE and CONSONANTS are lowercase

          • CaNoNiCaLSTuDLyCaPS THeMaPSaNDaBooKaReiNMyBRoWNFReNCHBaG --> VOWELS are lowercase and CONSONANTS are UPPERCASE ( used by the dyslexic )

          • MiXEdCapS TheMApsANdabOokaREINmyBrOWnFrencHBAG The Case of the letters change almost RANDOMLY


          Be aware that you may get some odd replacements, with some capitalizations. Just consider, these few examples, below, with the Proper Case capitalization rule :

          • If word = McDonald , Proper Case --> Mcdonald
          • If word = MacDonald, Proper Case --> Macdonald
          • If word = Google’s, Proper Case --> Google’S
          • If word = A FBI Inspector, Proper Case --> A Fbi Inspector
          • If word = my.email@test.com, Proper Case --> My.Email@Test.Com
          • If word = John Smith III, Proper Case --> John Smith Iii

          From that list above, it’s obvious that we can’t build a search/replacement, with regular expressions, for the following capitalizations !

          • Title Case, and its variants
          • German Sentence Case and German mid Sentence Case
          • Sentence case and mid Sentence case
          • MiXEdCapS

          Indeed, these capitalizations have a lot of exceptions or rules, that closely depends on grammar and spelling, completely unreachable with regex S/R !!!


          For all the others kinds of capitalization, here is, below, a list of standard regex S/R that achieves the appropriate case modifications.

          I included, in that list, a “light” version of the “Sentence case”, which :

          • can handle successive sentences, in one go

          • correctly write the pronoun I, in an UPPERCASE way

          • Unfortunately, replaces Proper nouns and some specific words (as names of the days, …), in a lowercase way :-((


          About the following S/R, some hypotheses are supposed :

          • You must SELECT the area to apply a particular capitalization rule, FIRST

          • The Regular expression search mode is SET

          • The In selection option should be CHECKED, on opening the Replace dialog, because of the previous selection


          For UPPER CASE : SEARCH = (?-is).+ and REPLACE = \U$0

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HI GUYS : O’NEIL, AND I, CREATED A TEST. WHAT DO YOU THINK ABOUT IT? I QUITE LIKE THAT MP3 SONG! / ‘T_EST’ T-EST “ABC”.


          For Start Case / Proper Case : SEARCH = (?-is)(\w)(\w*) and REPLACE = \u\1\L\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER Hi Guys : O’Neil, And I, Created A Test. What Do You Think About It? I Quite Like That Mp3 Song! / ‘T_est’ T-Est “Abc”.


          For tOGGLE cASE : SEARCH = (?-is)([A-Z])|[a-z] and REPLACE = (?1\l:\u)$0

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hI GUYS : O’NeIL, AND i, CREATED a TEST. WhAT do YOU tHINk aBOUT it? I quite LIKE THAT Mp3 sONG! / ‘t_ESt’ t-eST “AbC”.


          For “light” Sentence case : SEARCH = (?-is)([a-zA-Z])(.*?)((?=\b[Ii]\b)|(?=[.?!](\h|\R|\z)))|([a-zA-Z])(.*) and REPLACE = \u\1\5\L\2\6

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER Hi guys : o’neil, and I, created a test. What do you think about it? I quite like that mp3 song! / ‘T_est’ t-est “abc”.


          For lower case /mid sentence case : SEARCH = (?-is).+ and REPLACE = \L$0

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hi guys : o’neil, and i, created a test. what do you think about it? i quite like that mp3 song! / ‘t_est’ t-est “abc”.


          For SCREAMING_SNAKE_CASE : SEARCH = (?-is)(\w+)|[^\w\r\n]+ and REPLACE = (?1\U\1:_)

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HI_GUYS_O_NEIL_AND_I_CREATED_A_TEST_WHAT_DO_YOU_THINK_ABOUT_IT_I_QUITE_LIKE_THAT_MP3_SONG_T_EST_T_EST_ABC_


          For snake_case : SEARCH = (?-is)(\w+)|[^\w\r\n]+ and REPLACE = (?1\L\1:_)

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hi_guys_o_neil_and_i_created_a_test_what_do_you_think_about_it_i_quite_like_that_mp3_song_t_est_t_est_abc_


          For KEBAB-CASE : SEARCH = (?-is)(\w+)|[^\w\r\n]+ and REPLACE = (?1\U\1:-)

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HI-GUYS-O-NEIL-AND-I-CREATED-A-TEST-WHAT-DO-YOU-THINK-ABOUT-IT-I-QUITE-LIKE-THAT-MP3-SONG-T_EST-T-EST-ABC-


          For Train-Case : SEARCH = (?-is)(\w)(\w*)|[^\w\r\n]+ and REPLACE = (?1\u\1\L\2:-)

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER Hi-Guys-O-Neil-And-I-Created-A-Test-What-Do-You-Think-About-It-I-Quite-Like-That-Mp3-Song-T_est-T-Est-Abc-


          For kebab-case : SEARCH = (?-is)(\w+)|[^\w\r\n]+ and REPLACE = (?1\L\1:-)

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hi-guys-o-neil-and-i-created-a-test-what-do-you-think-about-it-i-quite-like-that-mp3-song-t_est-t-est-abc-


          For PascalCase : SEARCH = (?-is)([a-zA-Z])([a-zA-Z]*)|[^a-zA-Z\r\n]+ and REPLACE = \u\1\L\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HiGuysONeilAndICreatedATestWhatDoYouThinkAboutItIQuiteLikeThatMpSongTEstTEstAbc


          For CamelCase / WikiCase : SEARCH = (?-is)([a-zA-Z])([a-zA-Z]+)|(\b|_)[a-zA-Z](\b|_)|[^a-zA-Z\r\n]+ and REPLACE = \u\1\L\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HiGuysNeilAndCreatedTestWhatDoYouThinkAboutItQuiteLikeThatMpSongEstEstAbc


          For lowerCamelCase : SEARCH = (?-is)([a-zA-Z])([a-zA-Z]+)|(\b|_)[a-zA-Z](\b|_)|[^a-zA-Z\r\n]+ and REPLACE = \u\1\L\2

          then : SEARCH = (?-is)([A-Z][a-z]+){2,} REPLACE = \l$0

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hiGuysNeilAndCreatedTestWhatDoYouThinkAboutItQuiteLikeThatMpSongEstEstAbc


          For StUdLyCaPs : SEARCH = (?-is)([a-zA-Z])[^a-zA-Z\r\n]*([a-zA-Z])?|[^a-zA-Z\r\n]+ and REPLACE = \u\1\l\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HiGuYsOnEiLaNdIcReAtEdAtEsTwHaTdOyOuThInKaBoUtItIqUiTeLiKeThAtMpSoNgTeStTeStAbC


          For StUdLyCaPs, variant 1 : SEARCH = (?-is)([a-zA-Z])[^a-zA-Z\r\n]*([a-zA-Z])?|[^a-zA-Z\r\n]+ and REPLACE = \l\1\u\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hIgUySoNeIlAnDiCrEaTeDaTeStWhAtDoYoUtHiNkAbOuTiTiQuItElIkEtHaTmPsOnGtEsTtEsTaBc


          For StUdLyCaPs, variant 2 : SEARCH = (?-is)([aeiouy])|([B-DF-HJ-NP-TV-XZ])|[^a-zA-Z\r\n]+ and REPLACE = \u\1\l\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER hIgUYsOnEIlAndIcrEAtEdAtEstwhAtdOYOUthInkAbOUtItIqUItElIkEthAtmpsOngtEsttEstAbc


          For CaNoNiCaLSTuDLyCaPS : SEARCH = (?-is)([AEIOUY])|([b-df-hj-np-tv-xz])|[^a-zA-Z\r\n]+ and REPLACE = \l\1\u\2

          BEFORE Hi guys : o’nEil, and I, created A test. wHat DO you ThinK About IT? i QUITE like that mP3 Song! / ‘T_esT’ T-Est “aBc”.

          AFTER HiGuySoNeiLaNDiCReaTeDaTeSTWHaTDoyouTHiNKaBouTiTiQuiTeLiKeTHaTMPSoNGTeSTTeSTaBC


          Best regards and have a good day !

          guy038

          1 Reply Last reply Reply Quote 2
          • Marta ValerioM
            Marta Valerio
            last edited by Jun 9, 2016, 6:28 PM

            +1 for this feature. I really really need this feature. Please add this feature as soon as possible.

            Thanks in advance.

            1 Reply Last reply Reply Quote 0
            • zkirklandZ
              zkirkland
              last edited by Jun 10, 2016, 3:46 PM

              @Jeronymite:

              I created a small plugin called “FirstUpper” that does different types of capitalizations. I am adding more options as I have time.
              The current options are:

              • Capitalize Selected Title
                • Just select the text and hit Ctrl+Alt+U to properly capitalize the title according to the Chicago Manual of style.
              • Capitalize All Markdown Titles
                • Finds all markdown headings (Setext and Atx style) and properly capitalizes them.
              • Capitalize First Letter of All Sentences
                • Capitalizes the first letter of the first word of every sentence in the document. (one issue this has is with file extensions. It will capitalize “.txt” to “.Txt”.)

              I will be adding more features such as a convert to camelcase feature.

              I hope this helps!
              Zach

              1 Reply Last reply Reply Quote 0
              • ortomindO
                ortomind
                last edited by Dec 1, 2016, 5:14 PM

                @guy038
                I was struggle to make an expression to match a word that has at least one capital letter inside (not a lowercase) and replace that word to Start Case or Title Case
                here is an example:

                befOre: OnE teXT wIll Be transformed vERY welL

                After: One Text Will Be transformed Very Well

                if the word is lowercase or is already Start Case then it can stay as it is.

                I would appreciate any help!

                1 Reply Last reply Reply Quote 0
                • G
                  guy038
                  last edited by guy038 Dec 1, 2016, 9:01 PM Dec 1, 2016, 8:55 PM

                  Hello, ortomind,

                  Not very difficult, indeed !

                  In fact, the best would be to reverse your rules that you would like to ! So :

                  • If a word contains, ONLY, lowercase letters ( and possible digits and/or the underscore character ), just rewrite it

                  • ELSE, any word must be rewritten, with the Start Case capitalization rule


                  Therefore, a correct regex S/R could be :

                  SEARCH (?-i)\b[\l\d_]+\b|(\w)(\w*)

                  REPLACE (?1\u\1\L\2:$0)


                  NOTES :

                  • First, the in-line modifier (?-i) forces the regex engine to search in a sensitive way

                  • Then, due to | character, the regex engine must choose between the two alternatives :

                    • A Non-Empty range of Non_Upper characters [\l\d_]+, which must be a true word, due to the \b assertions, that surround it

                    • Any other word, containing, at least, one character, with two groups :

                      • The first character of the word, stored in group 1 ( (\w) )

                      • All the remaining characters of this word, stored in group 2 ( (\w*) )

                  • In replacement, the syntax represents a conditional replacement, based on group 1

                    • If group 1 exists, we rewrite this group ( the first character of a word ) uppercase ( \u\1 ), then, the group 2 ( All the remaining characters ) lowercase ( \L\2 )

                    • Else ( Group 1 do not exist ) we just rewrite the entire matched string ( the word, with NO uppercase letter ) ( $0 )


                  So, for instance, from the original text, below :

                  OnE teXT wIll Be trans_formed123 vERY welL
                  

                  After clicking of the Replace All button, you should obtain, with the regex S/R above, the modified text, below :

                   One Text Will Be trans_formed123 Very Well
                  

                  With the message Replace All: 7 occurrences were remplaced

                  Best Regards,

                  guy038

                  1 Reply Last reply Reply Quote 0
                  • ortomindO
                    ortomind
                    last edited by Dec 1, 2016, 10:07 PM

                    Dear guy038,
                    This works as it supposed and I thank you for it.
                    Could you tell me if there is a way to insert this in a macro?
                    Eventually how I can do at once in a macro all following 3 search/replace:
                    SEARCH (?-i)\b[\l\d_]+\b|(\w)(\w*)
                    REPLACE (?1\u\1\L\2:$0)
                    SEARCH ([^\s])([ ]{2,})([^\s])
                    REPLACE \1 \3
                    SEARCH [>:!?.] [A-Z]
                    REPLACE \L$0
                    thanks,
                    ortomind

                    Scott SumnerS 1 Reply Last reply Dec 2, 2016, 12:53 PM Reply Quote 0
                    • Scott SumnerS
                      Scott Sumner @ortomind
                      last edited by Dec 2, 2016, 12:53 PM

                      @ortomind

                      There is documentation on how to place search+replace in a macro, here: http://docs.notepad-plus-plus.org/index.php/Editing_Configuration_Files#Search_.2F_Replace_encoding

                      That may be a bit cryptic, but here’s one example of many that can be found, that show how to implement a real use-case: https://notepad-plus-plus.org/community/topic/11735/notepad-macro-not-working-correctly/2

                      You can adapt this example (which coincidentally also involves upper/lowercase manipulation!) for what you’re trying to do.

                      1 Reply Last reply Reply Quote 0
                      • G guy038 referenced this topic on Sep 12, 2023, 9:09 AM
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors