regexrubyminecase-conversion

How to use Regex to convert initial letter of a string to upper case


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"


Solution

  • 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

    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.