[英]In sentence how to make first letter UPPERCASE followed by dot ('.') and space (zero or more than one )
var t = ".i am krishna. france" // string // regular expression to match the pattern where $1 $2 $3 are the grouping t = t.replace(/[\\n]*([a-zA-Z]+[.][ \\n]*)([a-zA-Z])([a-zA-Z]*)[\\n]*/, '$1' + '$2'.toUpperCase() + '$3'); $('body').append(t); //to convert function convert() { return arguments[0].toUpperCase(); }
<html> <head> <title></title> </head> <body></body> </html>
.I am krishna. France
([.]\s*)([a-zA-Z])
您可以使用它代替,并替换为'$1'+'$2'.toUpperCase()
以实现所需的功能。
参见演示。
您可以使用:
t = t.replace(/(\. *)([a-z])/g, function($0, $1, $2) { return $1 + $2.toUpperCase(); });
//=> .I am krishna. France
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.