what is javascript regular expression and how to use

What is JavaScript regular expression?

In general,Regular expressions are patterns used to match character combinations in strings. In JavaScript regular expression are objects.

Regular expression nothing but one type of an object, that describes a pattern of character.

Mostly regular expressions are using for pattern matching performance and “search-and-replace” functions on the text.

Example :

/finalhints/i  – show as a regular expression

finalhints  – seems as a pattern which use for search

i  – seem as a modifier, that will be in case-sensitive.

Regular Expression seems to be like :  /pattern/modifiers;

Regular Expression – Using String Methods

In JavaScript, regular expressions are mostly use two string methods: replace() and search().

 The search() regular expression string method use for searching matches and return the position of matches.

The replace() regular expression string method use for replacing the pattern.

Regular expressions can make your search more powerful.

Regular Expression Modifiers

i – perform as a case-sensitive

g perform as a global match.(It will not stop after matching first match)

m – perform as a multiple matching.

here, I mention two best site that helped me lot to check my javascript regular expression:

Those sites also explain your regular expression by debugging your regular expression and explain which sub expression accept which type of character sequence.

Happy coding; 😉

Leave a Reply

Your email address will not be published. Required fields are marked *