Not directly with json_encode. All PHP does is create arrays and objects containing simple scalar types. It cannot create JS objects like RegExp or call JS functions directly. If all you're going to pass is that sample data in the question you can always do
$array = [
'regex' => '/some-regex/'
];
$js_string = '';
foreach($array as $key => $value) $js_string .= '"' . $key . '": new RegExp("' . $value ' "),';
return '{' . $js_string . '}';
That's really clunky code and, of course, it falls apart if $array contains anything but regular expressions (and it assumes that everything in there is safe for JS). But if that's all you have to do...
Wait! Is there a better way?
Indeed there is. The better thing to do is have json_encode do it's thing (it's kinda made to handle JSON) and then have your JS create the objects itself
let regex_list = <?php echo json_encode($array) ?>;
let myregex = {};
regex_list.forEach(function(regex, index) {
myregex[index] = new RegExp(regex);
});
This is a much cleaner solution. We don't have to worry about the data coming from PHP, so JS can take it from there and build a JS object that holds all the RegExp objects you want to create
{"regex": /some-regex/}is not valid JSON.let pattern = new RegExp(theRegexString)and then usepatterninstead of the regex.{regex: new RegExp(/some/)}. In otherwords, have a RegExp Object as an object property.new Regexp()isn't necessary.