I've come up with this regex that finds all words that start with $
and contain _
underscores:
\$(\w+)_(\w+)
I'm basically searching for variables, like $var_foo
etc.
How do I replace stuff using the regex groups?
For example, how can I remove the underscore and make the next letter uppercase, like $varFoo
?
How to use RegEx with . replace in JavaScript. To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring.
To use regular expressions in Sublime Text, first activate them in the corresponding search panel by clicking on the available buttons or using keyboard shortcuts. If you don't activate regular expressions before performing a search, the search terms will be interpreted literally. Documentation on regular expressions.
For example, the replacement pattern $1 indicates that the matched substring is to be replaced by the first captured group.
The replacement expression is:
\$\1\u\2
\1
, \2
are the captures (or $1
, $2
)\u
up-cases (see the Replacement String Syntax section).See the Regular Expressions chapter (in the TextMate docs) for more information.
There's already a package that does this, and more:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With