Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

Today, we are going to do how I find lowercase letters in a string, here we will use some common regex to find all lowercase letters from a string.

Here, we will learn to check whether lowercase letter contains in string or not also, and if contain it will return as a string and array format.

  • To remove lowercase letters from the string we will use the javascript replace() method and it will return the rest lowercase letter in the type of string.

  • To find the lowercase letter in string and return it in the form array we will use the javascript match() method.

Let’s plan out what we are going to do in this tutorial.

  1. Find lowercase letters and get them in string
  2. Find lowercase letters and get in array

Let’s start today’s tutorial How to find lowercase letters in a string javascript?

Find lowercase letters and get in the string

In this example, To find lowercase letters we will use regex and javascript replace() method.

const str = "InfinitBility";

const upperStr = str.replace(/[A-Z]/g, '');
console.log(upperStr); // 👉️ 'nfinitility'

In the above example, we replace uppercase letters with empty and return the rest strings.

The Output should show nfinitility only. let’s check it.

javascript, find lowercase letters in a string example
javascript, find lowercase letters in a string example

Find lowercase letters and get in array

In this example, To find lowercase letters we will use the regex and javascript match() method to get the rest string in an array.

const str = "InfinitBility";

const upperStrArr = str.match(/[^A-Z]/g, '');
console.log(upperStrArr); // 👉️ [ 'n', 'f', 'i', 'n', 'i', 't', 'i', 'l', 'i', 't', 'y' ]

In the above example, we find lowercase letters in the string and returning char in the array.

The Output should show [ 'n', 'f', 'i', 'n', 'i', 't', 'i', 'l', 'i', 't', 'y' ] only. let’s check it.

javascript, find lowercase letters in a string example
javascript, find lowercase letters in a string example

I hope it’s help you, All the best 👍.