
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- How can we capitalize only first letter of a string with the help of MySQL function/s?
- Pandas dataframe capitalize first letter of a column
- MySQL query to update all records to capitalize only the first letter and set all others in lowercase
- Capitalize first letter of a column in Pandas dataframe
- How to capitalize the first letter of each word in a string using JavaScript?
- Python program to capitalize each word's first letter
- Styling First-Letters with CSS ::first-letter
- Capitalize letter in a string in order and create an array to store - JavaScript
- Java Program to Print first letter of each word using regex
- Capitalize a word and replace spaces with underscore - JavaScript?
- Print first letter of each word in a string using C# regex
- JavaScript Regex to remove text after a comma and the following word?
- Capitalizing first letter of each word JavaScript
- Getting first letter of each word in a String using regex in Java
- Grouping names based on first letter in JavaScript
Advertisements