2

Given a bunch of strings in an editor (e.g., Rubymine or IntelliJ) that look like this:

list: ["required","TBD at time of entry", "respirator, gloves, coveralls, etc."]

How can I use the built-in Regex search and replace to convert the initial letter to upper case?

To this:

list: ["Required","TBD at time of entry", "Respirator, gloves, coveralls, etc."]

NOTE WELL: The "TBD" should remain as "TBD" and not "Tbd"

Jon Kern
  • 3,186
  • 32
  • 34

2 Answers2

2

(IntelliJ and RubyMine have Java regex rules in force I think.)

(For my future self) I used the following regex:

Search: "(?)([a-z])

Replace: "\U$1\E

BTW: Was not able to figure out why upper case letters were also selected. (shrug)

enter image description here

And it worked!

Jon Kern
  • 3,186
  • 32
  • 34
2

You may match any lowercase letter that is preceded with a ":

Search:   (?<=")\p{Ll}
Replace\U$0

See the regex demo. Check Match Case to ensure matching only lower case letters.

Details

  • (?<=") - a positive lookbehind that ensure that the preceding char is a "
  • \p{Ll} - any Unicode lowercase letter.

Note that \U - uppercase conversion operator - does not require the trailing \E if you needn't restrict its scope and $0 backreference refers to the whole match value, no need to wrap the whole pattern with a capturing group.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563