在句子中如何使第一个字母大写,后跟点('.')和空格(零或多个)

In sentence how to make first letter UPPERCASE followed by dot ('.') and space (zero or more than one )

本文关键字:空格 何使 第一个 句子      更新时间:2023-09-26

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

您可以使用:

t = t.replace(/('. *)([a-z])/g, function($0, $1, $2) { return $1 + $2.toUpperCase(); });
//=> .I am krishna.   France
([.]'s*)([a-zA-Z])

您可以改用它并替换为'$1'+'$2'.toUpperCase()以实现您想要的。

请参阅演示。

https://regex101.com/r/sH8aR8/4