38

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:sequence

and want the result:

Some:Test:Sequence

I’m aware of things like \u$1 and \l$1, but they do not work in Atom, as Atom is using JS-style RegEx. The JS-RegEx solutions I found, however, always involve calling a function (see example here), which is not possible in Atom, afaik.

Does anyone know if there is a way to achieve this? I also don’t mind installing a package for a more powerful regex search/replace, but haven’t found one and I’d like to avoid writing one on my own just for this.

Please note: I’m not looking for a solution to find/select the characters. The selection works just fine and is a bit more complex as in the example.

Community
  • 1
  • 1
max
  • 1,509
  • 1
  • 19
  • 24
  • so you can not use regex ? and what about a custom function with pure JavaScript ? – Halayem Anis Feb 23 '15 at 12:47
  • I think you misunderstood my question. I am using regex already, I just can’t get replace-with-uppercase to work. Also, as I wrote, I don’t think calling any JS is possible without creating a package. – max Feb 23 '15 at 12:54
  • 1
    Atom *includes* Oniguruma regular expressions only for the grammars, in all other locations it uses standard JavaScript regular expressions. So to say Atom is "built on" Oniguruma is a bit of a misnomer. – Lee Feb 23 '15 at 15:25
  • Okay, thanks for the clarification, Lee. I assumed if there’s already a powerful regex engine available to Atom, they used it for other things, too, and just limited it somehow. I removed that part from the question. – max Feb 23 '15 at 15:38
  • 1
    I would really like to see that functionality included in Atom as well. – inteist May 15 '15 at 18:35
  • 3
    I opened a ticket for a related request: https://github.com/atom/atom/issues/7486 – Billybobbonnet Jun 27 '15 at 15:27
  • Dogpile here to help the cause: https://github.com/atom/find-and-replace/issues/417 – Techmag Sep 17 '15 at 15:12

4 Answers4

49

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:

Community
  • 1
  • 1
Aaron Critchley
  • 2,335
  • 2
  • 19
  • 32
14

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

Sergey Panarek
  • 141
  • 1
  • 2
1

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.

azt
  • 2,100
  • 16
  • 25
1

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
vishal munde
  • 333
  • 1
  • 3
  • 13