I have a camelcase string e.g. thisIsCamelcaseString
I'd like to remove the first lowercase characters from from the string.
To achieve this, I think I'm looking for a regular expression that will match from the first capital letter in the string to the end. In this example it would remove this
, returning:
IsCamelcaseString
I have a camelcase string e.g. thisIsCamelcaseString
I'd like to remove the first lowercase characters from from the string.
To achieve this, I think I'm looking for a regular expression that will match from the first capital letter in the string to the end. In this example it would remove this
, returning:
IsCamelcaseString
2 Answers
Reset to default 6This is one way to achieve it:
console.log('thisIsCamelcaseString'.replace(/^[a-z]+/, ''));
This uses the ^
anchor which matches the string from beginning and then searches for the smallcase letters.
You can use this regex
[A-Z]\S+
Demo
This matches the first capital letter with [A-Z] and then any other non-blank characters with \S+
.
If you want to match only letters you can use
[A-Z][a-zA-Z]+