Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript switch case regex

var regex1 = /a/,
    regex2 = /b/,
    regex3 = /c/,
    samplestring = 'b';

switch (true) {
    case regex1.test(samplestring):
        console.log("regex1");
        break;
    case regex2.test(samplestring):
        console.log("regex2");
        break;
    case regex3.test(samplestring):
        console.log("regex3");
        break;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: revert back to css 
Javascript :: discord.js add button to message 
Javascript :: javascript random word 
Javascript :: react 17 hot reload not working 
Javascript :: javascript pass all arguments to another function 
Javascript :: js invert color 
Javascript :: js for in object 
Javascript :: javascript count table rows 
Javascript :: javascript merge objects 
Javascript :: insert json file in python 
Javascript :: queryselector data attribute 
Javascript :: get execution time in javascript 
Javascript :: jquery close another dialog 
Javascript :: combinereducers 
Javascript :: how to check consecutive characters in javascript 
Javascript :: react array find index 
Javascript :: download file javascript 
Javascript :: fibonacci sums javascript 
Javascript :: limit characters display javascript 
Javascript :: faker.js name 
Javascript :: javascript parse xml 
Javascript :: javascript compare arrays remove duplicates 
Javascript :: sort divs alphabetically jquery 
Javascript :: javascript button 
Javascript :: install react router dom 
Javascript :: cra redux 
Javascript :: remove event listener jquery 
Javascript :: E: Unable to locate package npm 
Javascript :: how to auto refresh a div js 
Javascript :: File type node js 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =