Skip to content

Instantly share code, notes, and snippets.

@avataru
Last active June 16, 2021 18:10
Show Gist options
  • Save avataru/8404870 to your computer and use it in GitHub Desktop.
Save avataru/8404870 to your computer and use it in GitHub Desktop.
Sublime Text change case of back-reference during regex find and replace
When performing a regex find-and-replace in Sublime Text 2, the following modifiers may be used to change the case of a backreference during the replacement step:
\l : first character to lower case
\u : first character to upper case
\L : start of lower case conversion
\U : start of upper case conversion
\E : end lower/upper case conversion
(Conversion only applies to alpha-characters)
Example
Given an HTML file containing the following class attributes:
class="item-title"
class="item-description"
class="item-comment"
Your task is to remove the hyphen from the class name and replace it with a camel-cased version of the class name like so:
class="itemTitle"
class="itemDescription"
class="itemComment"
One solution is to perform the following regex find-and-replace:
Find What item-(.)
Replace With: item\u\1
Source: http://philquinn.co.uk/sublime-text-2-convert-regex-backreference-case/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment