繁体   English   中英

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

[英]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()以实现所需的功能。

参见演示。

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

您可以使用:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM