 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Capitalize only the first letter after colon with regex and JavaScript?
To capitalize only the first letter, use the concept of regular expression along with toUpperCase(). Since the toUpperCase() capitalize the entire string, we need to use Regex to only capitalize the first letter after colon.
Let’s say the following is our string −
var objectValues='fullName: john Smith';
Here’s the complete code to capitalize only the first letter after colon −
Example
var objectValues='fullName: john Smith'; function capitalizeFirstAfterTheColon(value){    return value.replace(/([:\?]\s+)(.)/g, function(data) {       return data.toUpperCase();    }); } console.log(capitalizeFirstAfterTheColon(objectValues)); To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo85.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo85.js fullName: John Smith
Advertisements
 