Change case with javascript regex

How to change the case of some backlink in String.replace()? I want to match some part of the text and change its case to upper / lower.

+5
source share
2 answers

You can use a regular expression to match you and then pass a function, here is an example of converting CSS properties:

"margin-top".replace(/-([a-z])/, function(a, l) { return l.toUpperCase(); })
//result = "marginTop"

. -alpha ( ) -upperalpha, , , .toUpperCase() .toLowerCase() ( - ) , .

+6

, .

- :

myString.replace(/AnyCasE/gi, "anycase")
-2

All Articles