“JavaScript Regex Exxchar” Kode Jawaban

JavaScript Regex Exxchar

var r = /^a$/

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

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] }
*/
Puzzled Puffin

Jawaban yang mirip dengan “JavaScript Regex Exxchar”

Pertanyaan yang mirip dengan “JavaScript Regex Exxchar”

Lebih banyak jawaban terkait untuk “JavaScript Regex Exxchar” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya