Atom Editor: RegEx replace to uppercase/lowercase

后端 未结 4 668
刺人心
刺人心 2020-12-29 19:16

I\'m trying to replace some characters in a string with their uppercase/lowercase equivalents in Atom Editor.

Let’s say I have the string:

some:test:         


        
相关标签:
4条回答
  • 2020-12-29 20:05

    Note that whilst you said the question is not about the selection, I'm using a more simplified example.

    If you have a string consisting of: This is a Mixed case String! I want every Letter to Start with A Capital.

    You can use the Regex selector of \b\w to find the first characters of every word in the string. (Done by Cmd + F and clicking .* on the right hand menu for Regex search)

    Now press Alt + Enter to select all of the found results, this should highlight all results of the Regex query. Following this, to make every first letter uppercase you can press Cmd + K -> Cmd + U, you can modify them however you want from here.

    Boom! The string should now look like: This Is A Mixed Case String! I Want Every Letter To Start With A Capital.

    I've been looking for an answer for this question for a while, here are my sources for the answer:

    • arturomp's answer on modifying text (docs included in answer)

    • johno's answer on how to select all results from a Regex search (Relevant pull request included in answer)

    0 讨论(0)
  • 2020-12-29 20:09

    Press alt + enter to select all matches, next go to menu: Edit --> Text --> Upper or Lower case

    0 讨论(0)
  • 2020-12-29 20:20

    A straight-forward kind-of solution within the framework of plain Regex would be to do the replacement for each character separately. This is probably not practical (if you have to trigger each replacement manually), but it works.

    Search for all lower-case 'a' at the beginning of each word, replace it by the upper-case 'A'. Then 'b' for 'B', ... until you have all characters relevant for your target language/character set.

    0 讨论(0)
  • 2020-12-29 20:23

    For me, It worked with Regex selector of \s\w to find the first characters of every word in the string.

    For Mac :

    cmd + F -> \s\w -> click on .* -> option+enter -> cmd+K -> cmd+U
    
    0 讨论(0)
提交回复
热议问题