2948 explained code solutions for 75 technologies


javascriptUse variable as regex


var regex = new RegExp('[0-9]+', 'g');
var matches = 'test_str_1'.match(regex);ctrl + c
var regex

declares new regular expression from string

'[0-9]+'

string representation of our regular expression

'g'

which modifiers to use (global in this case)

matches

will contain an array of found matches

'test_str_1'.match(regex)

matches text string 'test_str_1' agains our regex regular expression