I have the following string:
[(33, 165) (1423, 254)]
How can I bring the 4 numbers into an Array? I tried with regex so far.
Result should be an array containing 33,165,1423,254.
I can use a PHP and Javascript solution.
I have the following string:
[(33, 165) (1423, 254)]
How can I bring the 4 numbers into an Array? I tried with regex so far.
Result should be an array containing 33,165,1423,254.
I can use a PHP and Javascript solution.
There you go:
<?php
$string = '[(33, 165) (1423, 254)]';
$regex = '~\d+~';
preg_match_all($regex, $string, $numbers);
print_r($numbers);
?>
I don't know for what you are using this and why you require this.
But if [(33, 165) (1423, 254)]
is a string, below php code can be used to create an array of the numbers in this string.
<?php
$string = "[(33, 165) (1423, 254)]";
$string = str_replace([" ","(","[","]"], "", $string);
$string = str_replace(")", ",", $string);
$array = explode(",", $string);
print_r($array);
OUTPUT
Array ( [0] => 33 [1] => 165 [2] => 1423 [3] => 254)