Tech Study

Javascript Regex Match

A javascript regular expression is a search pattern that is formed by the order of characters that is used for operations such as text search and replacement.

What is javascript regex match?

Javascript Regex match is a powerful tool for matching patterns in text. It can be used to search, edit, and manipulate text, as well as to validate input in forms and other applications.

JavaScript has built-in support for regular expressions through the RegExp object. Regular expressions are used to search, match, and manipulate strings.

Syntax for Javascript Regex Tester :

Regular expression literal:

const regex = /pattern/;

RegExp constructor: 

Creating regex using string

regex = new RegExp('pattern');

Example for online javascript regex tester:

Example 1 :

Here is an example to match a word in a sentence:

In this code of javascript regex tester, We will learn how to search “football” word in the string

let regex = /football/;

let string = "The football world cup was recently won by Argentina";

let match = string.match(regex);

// Now just print out match

console.log(match);

The string “The football world cup was recently won by Argentina” is searched for using a regular expression (/football/)

This gives the following output-:


'football',

index: 4,

input: 'The football world cup was recently won by Argentina',

groups: undefined

}

The outcome for following javascript regex match, Index is 4 as the string ‘football’ starts from the 4th index in the input string.

Example 2:

You can also use the test() method to check if a Javascript Regex Match a string, following is the javascript regex tester code :

let regex = /football/;

let string = "The football world cup was recently won by Argentina";

console.log(regex.test(string)) // Output is true

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more