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])
You can use this instead and replace by '$1'+'$2'.toUpperCase()
to achieve what you want.
See demo.
You can use:
t = t.replace(/(\. *)([a-z])/g, function($0, $1, $2) { return $1 + $2.toUpperCase(); });
//=> .I am krishna. France
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.