Suppose I need a single value from a string, say a version number. Should I use exec() or match()?
Snippet1
res1 = /(\d+\.\d+)/.exec(some_string)[0];
vs
Snippet2
res1 = some_string.match(/\d+\.\d+/)[0];
which is better?
Suppose I need a single value from a string, say a version number. Should I use exec() or match()?
Snippet1
res1 = /(\d+\.\d+)/.exec(some_string)[0];
vs
Snippet2
res1 = some_string.match(/\d+\.\d+/)[0];
which is better?
 
    
    You can measure the performance of your code using https://jsbench.me/.
 
    
     
    
    It'd use match because it can be kept on one line, but it's a matter of taste.
