To test if a regex matches and assign it to a variable if it does, or assign it to some default value if it doesn't, I am currently doing the following:
var test = someString.match(/some_regex/gi);
var result = (test) ? test[0] : 'default_value';
I was wondering if there is any way to do the same thing in JS with one line of code.
Clarification: I am not trying to make my code smaller, but rather make it cleaner in places where I am defining a number of variables like so:
var foo = 'bar',
foo2 = 'bar2',
foo_regex = %I want just one line here to test and assign a regex evaluation result%