Literal Characters


In regular expressions most characters like alphabets, digits and several other characters match themselves exactly i.e., they are literal matches for themselves. For example, a matches a, b matches b, A matches A, 2 matches 2 etc

let pattern1 = /abc/; //matches text containing the sequence abc
let pattern2 = /XYZ/; //matches text containing the sequence XYZ
let pattern3 = /pq,45@6rs#/; //matches text containing the sequence pq,45@6rs#

The pattern /lin/ has one match in the string ‘A plinth of 4 by 4’. The pattern /bada/ is found twice in ‘bada bing, bada boom’ as seen in the following code

let pattern = /bada/dg;
let input = 'bada bing, bada boom';
let matches = input.matchAll(pattern);
let i = 1;
for (let match of matches) {
console.log(`----------Match ${i}-------------`);
for (text of match) {
console.log(text);
}
let index = match.index;
console.log("index = " + index);
let inputStr = match.input;
console.log("input = " + inputStr);
let indices = match.indices;
for (let [first, last] of indices) {
console.log("indices = (" + first + "," + last + ")");
}
console.log("\n");
i ++;
}

If two characters are required to appear next to one another then it is called ‘concatenation‘.
In the pattern /bada/, the characters ‘b’, ‘a’, ‘d’ and ‘a’ are concatenated together