简体   繁体   中英

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> 

Expected result:

.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.

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

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.

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