[英]Regex match from first uppercase character in string
I have a camelcase string eg thisIsCamelcaseString
我有一个
thisIsCamelcaseString
字符串,例如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: 在此示例中,它将删除
this
,返回:
IsCamelcaseString
This is one way to achieve it: 这是实现它的一种方法:
console.log('thisIsCamelcaseString'.replace(/^[az]+/, ''));
This uses the ^
anchor which matches the string from beginning and then searches for the smallcase letters. 这使用从一开始就匹配字符串的
^
锚,然后搜索小写字母。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.