Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript regex exact match

var r = /^a$/

function matchExact(r, str) {
   var match = str.match(r);
   return match && str === match[0];
}
Comment

js regexp match

// 1. Match indices for numbered group
const matchObj = /(a+)(b+)/d.exec('aaaabb');

console.log(matchObj);
/*
Output -
['aaaabb', 'aaaa', 'bb', index: 0, input: 'aaaabb', groups: undefined, indices: Array(3)]
*/
// then
matchObj.indices[1];
/*
Output - 
[0, 4]
*/
// -------------------------

// 2. Match indices for named groups
const matchObj = /(?<as>a+)(?<bs>b+)/d.exec('aaaabb');

console.log(matchObj);
/*
Output - 
['aaaabb', 'aaaa', 'bb', index: 0, input: 'aaaabb', groups: {as: 'aaaa', bs: 'bb'}, indices: Array(3)]
*/
// then
matchObj.indices.groups;
/*
Output -
{ as: [0,4], bs: [4,6] }
*/
Comment

js regexp match

// ES2022
const matchObj = /(a+)(b+)/d.exec('aaaabb');

console.log(matchObj);
/*
Output -
['aaaabb', 'aaaa', 'bb', index: 0, input: 'aaaabb', groups: undefined, indices: Array(3)]
*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: google recaptcha reload 
Javascript :: Find a character between space with Regex in js 
Javascript :: how to check if the element exist in the parent element javascript 
Javascript :: chai test throw error 
Javascript :: jquery selector id ends with 
Javascript :: how to deploy nextjs app on netlify 
Javascript :: upload file angular 
Javascript :: jspdf create table 
Javascript :: js window onload 
Javascript :: usememo hook react 
Javascript :: delete last character from string js 
Javascript :: THE REDUCE() METHOD IN JAVASCRIPT 
Javascript :: loop through json array python 
Javascript :: how to import json in js 
Javascript :: execcommand js 
Javascript :: js object deep clone with lodash 
Javascript :: javascript object destructing 
Javascript :: replace is not working in javascript 
Javascript :: js add multiple element to document 
Javascript :: rgb to hex conversion 
Javascript :: react-select 
Javascript :: async await iife 
Javascript :: TypeError: Object of type ndarray is not JSON serializable 
Javascript :: javascript change css opacity duration 
Javascript :: zustand simple counter 
Javascript :: string remove last two characters javascript 
Javascript :: base64 encode in javascript 
Javascript :: antd tag 
Javascript :: prevent duplicate entries in javascript array 
Javascript :: react hide element 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =