JAVASCRIPT JOURNEY - DAY 9

#teamtanayejschallenge

CHAPTER 9 :REGULAR EXPRESSIONS

1.jpg

Regular expressions are a necessity of software development. They are high-speed, performant tools that allow you to find and replace patterns in a text.

With this,

  1. check if a text contains a particular substring or pattern. 2 find and return those pattern matches. 3 capture these substrings out of the text. 4 modify the captured substrings.

But how in JS? IN JS :

A regular expression is an object that describes a pattern of characters.

In JavaScript, you can define regular expressions in two different ways:

1.

const Pattern = /Medi[a-zA-Z]*/;
where it looks like /<RE>/
  1. creating an instance of the RegExp object:
const Pattern = new RegExp (“Medi[a-zA-Z]*”);

WHAT IS REGEX THEN?

Any alphanumeric character that’s not a special meta-character or an operator will match itself in a regex.

Definitions and theoritical concept is prior here.

CAPTURES/BACKREFERENCES

When parentheses surround a part of a regex, it creates a capture.

Say we want to match an HTML tag, we can use a regular expression that looks like this: /<([a-z]\w)\b[^>]>/

SO BORING! GET INTO ITS DETAIL WHERE YOU FIND ITS UTMOST USE:

Regular expressions are often used to validate the user’s input, but frequently they can cause a bad user experience — especially when the programmer makes assumptions about the user input.

SO BEWARE OF THAT FACT!!!

Generally overuse of them in forms and inputs frustrate users. So use them when required! Front-End Dev doesn't give it much importance

But it is a good part of EJS6.

Happy Learning:-)