xxxxxxxxxx
const str = 'hello world!';
const result = /^hello/.test(str);
console.log(result); // true
/**
The test() method executes a search for a match between
a regular expression and a specified string
*/
xxxxxxxxxx
// .test(string) is a method of the RegExp class
// returns a boolean value
// .match(regexp) is a method of the String class
// if global flag (g) is included, returns an array of matched instances
const str = "A text string!";
const reg = /t/g; // matches all lower case "t"s
reg.test(str); // returns true
str.match(reg); // returns ['t', 't', 't']
xxxxxxxxxx
let text = "abcdefghijklmnopqrstuvxyz";
let pattern = /e/;
pattern.test(text)
/*searches for pattern in text*/
Test grepper on SO
xxxxxxxxxx
console.log(/^([a-z0-9]{5,})$/.test('abc1')); // false
console.log(/^([a-z0-9]{5,})$/.test('abc12')); // true
console.log(/^([a-z0-9]{5,})$/.test('abc123')); // true
Run code snippet
xxxxxxxxxx
const regexTester = (regex, str) => {
const regexObj = new RegExp(regex);
return regexObj.test(str);
};
// Example usage
const regexPattern = /[a-z]+/;
const inputString = "hello";
console.log(regexTester(regexPattern, inputString)); // Output: true
xxxxxxxxxx
// Sample regular expression test in JavaScript
const regex = /pattern/; // Replace "pattern" with your desired pattern
const str = 'Hello, world!';
const result = regex.test(str); // Test the pattern against the string
console.log(result); // Output: true or false based on whether the pattern is found or not
xxxxxxxxxx
// Elimina los diacríticos de un texto (ES6)
//
function eliminarDiacriticos(texto) {
return texto.normalize('NFD').replace(/[\u0300-\u036f]/g,"");
}